Use PHP to create cron job

旧街凉风 提交于 2020-01-16 04:21:32

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!