I am beginner in programming and I was trying to set up Cron Job using PHP script in couple ways, which I found on the internet, but I always run into some errors I can't fix by myself: First method:
exec('echo -e "`crontab -l`* * {$_POST['birthDay']} {$_POST['birthMonth']} * /home/jharvard/vhosts/pset7/public/{$_POST['lastname']}{$_POST['firstname']}.php" | crontab -");
,but I think error appears because of ` symbol and I am sure a lot of ' symbols os not good either.
Second method:
echo "* * {$_POST['birthDay']} {$_POST['birthMonth']} * /home/jharvard/vhosts/pset7/public/{$_POST['lastname']}{$_POST['firstname']}.php" | tee -a /var/spool/cron/root
Error is: ( ! ) Parse error: syntax error, unexpected 'var' (T_VAR) in /home/jharvard/vhosts/pset7/public/calendar.php on line 24
Third try:
$cron_file = "{$_POST['lastname']}{$_POST['firstname']}";
// Create the file
touch($cron_file);
// Make it writable
chmod($cron_file, 0777);
// Save the cron
file_put_contents($cron_file, "* * {$_POST['birthDay']} {$_POST['birthMonth']} * /home/jharvard/vhosts/pset7/public/{$_POST['lastname']}{$_POST['firstname']}.php");
//Install the cron
exec('crontab cron_file');
I have no idea why this one doesn't work. I execute
crontab -l
, but it doesn't show any new jobs