I wrote a php script that is intended to run from a bash script in terminal. I installed PHP5 php-cli and php-pear. THe PHP Scripts runs smoothly in apache server using a browser but it does nothing when run from terminal. I also make it to be executable with read and write permission to all. I will put that bash script to run in cron jobs every 5 minutes.
#!/usr/bin/php5 -q
<?php
$file="/var/www/floods/php/indx.txt";
$indx=file_get_contents($file);
$con = mysql_connect("localhost","user","password");
if(!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("smsgw",$con);
$acc = mysql_query("SELECT * FROM accounts");
while($fld = mysql_fetch_array($acc)){
$index[]=$fld['id'];
$num_reg[]=$fld['num'];
$loc[]=$fld['location'];
}
if(isset($index)){
$inbox = mysql_query("SELECT * FROM inbox");
while($fields=mysql_fetch_array($inbox)){
$id[]=$fields['id'];
$num_inbox[]=$fields['number'];
$smsdate[]=$fields['smsdate'];
$text[]=$fields['text'];
}
$last_indx=count($id);
$last_num=count($index);
for($i=0;$i<$last_num;$i++){
for($j=(int)$indx;$j<$last_indx;$j++){
if(strcmp($num_inbox[$j],$num_reg[$i])==0){
$file_save= $num_reg[$i] . ".txt";
file_put_contents($file_save,$text[$j]);
}
}
}
}/*End*/
?>
Thanks for those who comments and help. Finally solved the Problem. I should specified the exact path where to save the text files. $file_save= $num_reg[$i] . ".txt";
should be like this $file_save="/path/where/to/save". $num_reg[$i] . ".txt";
$file_save="/path/where/to/save". $num_reg[$i] . ".txt";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.