php - Cron is executed but script doesn't work - Ask Ubuntu


i know there lot of similar question , i've tried lots of things still can't make work.

i have cronjob scheduled run on 10min. can see in /var/log/syslog run normally

oct 21 07:30:01 stan cron[7604]: (stan) cmd (stan /home/stan/update.sh) oct 21 07:40:01 stan cron[8304]: (stan) cmd (stan /home/stan/update.sh) oct 21 07:50:01 stan cron[8751]: (stan) cmd (stan /home/stan/update.sh) oct 21 08:00:01 stan cron[9347]: (stan) cmd (stan /home/stan/update.sh) oct 21 08:10:01 stan cron[9789]: (stan) cmd (stan /home/stan/update.sh) 

update.sh call php script update database. when run directly terminal shell script database got updated , it's working perfectly

./update.sh 

but cronjob doesn't update database. cron

*/10 * * * * stan /home/stan/update.sh 

command produced shell script

/usr/bin/php /var/www/html/site/update.php 

permissions of both files

-rwxrwxr-x  1 stan stan    123 oct 20 15:09 update.sh -rwxr-xr-x  1 stan www-data 1301 oct 21 07:52 /var/www/html/site/update.php 

any idea can problem?

update: path

$ echo $path /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin 

update.sh

$ cat update.sh  
#!/bin/sh  list="/var/www/html/site" config="/usr/bin/php"  in "$list"     "$config" "$i"/update.php done 

reference question yesterday shell , php cron.

$ whereis php  php: /usr/bin/php5.6 /usr/bin/php /usr/lib/php /etc/php /usr/include/php /usr/share/php5.6-intl /usr/share/php7.0-mbstring /usr/share/php7.0-common /usr/share/php5.6-curl /usr/share/php5.6-gd /usr/share/php5.6-mcrypt /usr/share/php5.6-common /usr/share/php5.6-readline /usr/share/php5.6-json /usr/share/php /usr/share/php5.5-mbstring /usr/share/php5.6-opcache /usr/share/php5.6-mbstring /usr/share/php5.6-xml /usr/share/php5.5-common /usr/share/php5.6-mysql /usr/share/man/man1/php.1.gz 

$ php /usr/bin/php 

you seem confusing 2 different methods of invoking cron jobs.

ubuntu inherits debian confusing policy of supporting both user crontabs stored in spool area /var/spool/cron, , system-wide cron jobs run /etc/crontab , files in /etc/cron.d.

jobs specified in /etc/crontab or via files in /etc/cron.d need field in order allow them run different user format like

*/10 * * * * <username> <command> <args> 

jobs set via spool area using crontab -e (or sudo crontab -e root) belong specific user, , don't need user field

*/10 * * * * <command> <args> 

if include username field in cron job set via crontab -e command, misinterpreted command: can see log output,

oct 21 07:30:01 stan cron[7604]: (stan) cmd (stan /home/stan/update.sh) 

cron interpreting stan command argument /home/stan/update.sh

the solution should remove username stan crontab.


Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User

sql server - "Configuration file does not exist", Event ID 274 - Super User