Note that there are some explanatory texts on larger screens.

plurals
  1. POMake a part of script run after another
    text
    copied!<p>i have a problem. I have a script, that sends files to email after N time(executed from crontab) The problem is, that i try to make an output from maillog to mysql.</p> <p>here is a script</p> <pre><code>#!/usr/bin/php &lt;?php date_default_timezone_set("Europe/Chisinau"); $faxdir = '/var/spool/fax/'; $dir = opendir("/var/spool/fax/"); while(($file = readdir($dir)) !== false){ if (($file != ".") &amp;&amp; ($file != "..")){ $mytime = date('d-m-Y H:i:s'); $sendfile = $file; $findcaller = explode('_', $file); $findcaller = explode('-', $file); $findsrc = shell_exec('echo "'.$findcaller[0].'" | sed "s/[^_]*\_//"'); $findsrc = str_replace(array("\r","\n"),"",$findsrc); $caller = shell_exec('echo "'.$findcaller[1].'" | sed "s/[^_]*\_//"'); $cutbillid = shell_exec('echo "'.$file.'" | sed "s/[^_]*\_//"'); $findnumber = shell_exec('echo "'.$cutbillid.'" | sed "s/[^-]*\-//"'); $findnumber=str_replace(array("\r","\n"),"",$findnumber); $key = '.TIF'; $number=preg_replace('/'.$key.'.*/','',$findnumber); $showstatus = shell_exec('/usr/sbin/lsof | grep "'.$faxdir.'"*"'.$number.'"'); if ($showstatus &lt;&gt; ""){ exit(0); }else{ $db_link = mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error()); mysql_select_db("centrexdb"); $query = mysql_query("SELECT `fax2email` FROM users WHERE username='".$number."' AND faxstatus='1'"); $fax2email = mysql_fetch_array($query); if ($fax2email[0] == ''){ $currdate = shell_exec('echo "'. date('Y-m-d_H:i:s') .'"'); $noemail = shell_exec('mv /var/spool/fax/"'.$file.'" /var/spool/fax-nomail/"'.$currdate.'"--"'.$file.'"'); } else { $findcaller = explode('_', $file); $findcaller = explode('-', $file); $caller = shell_exec('echo "'.$findcaller[1].'" | sed "s/[^_]*\_//"'); $caller=str_replace(array("\r","\n"),"",$caller); $sendmail = shell_exec('echo | mutt -a "'.$faxdir.'""'.$sendfile.'" -s "Fax From '.$findsrc.' to '.$number.'" "'.$fax2email[0].'"'); echo "executing"; unlink(''.$faxdir.''.$sendfile.''); } mysql_close($db_link); } } sleep(45); $dbnew = mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error()); mysql_select_db("FAX"); $myresult=shell_exec('cat /var/log/maillog |grep "to=&lt;'.$fax2email[0].'&gt;" |tail -n1'); echo $myresult; $currentdate = shell_exec('echo "'. date('Y-m-d_H:i:s') .'"'); $umail = $fax2email[0]; mysql_query("INSERT into faxlog (Date, UserNumber, SourceNumber, UsedEmail, MailLog) VALUES('$mytime', '$number', '$findsrc', '$umail', '$myresult')"); mysql_close($dbnew); sleep(5); } exit(0); ?&gt; </code></pre> <p>The problem is that if in folder are more than 1 file, for first file script returns from log past value because the log needs a time to be written. I done tail -f /var/log/maillog and i have found that mail command executes after a 45s delay. As i understand i need to run main block with file sending and after a delay(for log to be written) get the log content. So how can i do it?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload