问题
I'm trying to make an alarm clock with a webinterface (on my Raspberry Pi).
I want to make this with PHP and crontab.
This is my PHP code:
shell_exec("./wake.sh $minutes $hours $days");
This is the wake.sh script:
echo "number 1: $1; number 2: $2; number 3: $3" | wall;
(crontab -u $USER -l; echo "$0 $1 * * $2 /var/www/alarm.sh") | crontab -u $USER -
If I run the script from bash (from the www-data user), I get the broadcast message and an entry in the crontab file, but if I run it from the PHP script, the broadcast message is sent, but there is no entry in the crontab file.
回答1:
I finally found out the answer: the $USER
variable is empty, if I execute it from PHP.
Now I use:
(crontab -l; echo "$0 $1 * * $2 /var/www/alarm.sh") | crontab -
and it works!
来源:https://stackoverflow.com/questions/27058140/use-php-to-create-cron-job