I have Raspberry Pi with Raspbian installed on it.
I need a cron job that needs to have a variable time period (every 10, 20, 30, 40, 50 or 60 minutes). I found out the easiest way to create new cron job without editing crontab file is to create new file in
/etc/cron.d. My file
/etc/cron.d/myCron looks like this:
*/10 * * * * root /home/pi/myScript >> /home/pi/myLog.log 2>&1
and its owner/permissions:
-rw-r--r-- 1 root root 84 Sep 9 16:15 myCron
Now I need to write to this file via php script, something like this:
<?php $config = $_GET["config"]; $cron = fopen('/etc/cron.d/myCron','w'); fwrite($cron,"*/".$config['interval']." * * * * root /home/pi/myScript >> /home/pi/myLog.log 2>&1") fclose($cron); ?>
in order to change the time period.
Problem is, php is run by user
www-data and the files in
cron.d directory needs to be owned by
root and has to have permissions
-rw-r--r--, otherwise it will not work.
Any ideas on how can I achieve this? Thanks!