How to remove or delete single cron job using linux command?
I have created cron jobs for my site which is listed below and they are working fine. I print all cron job by using this PHP script:
$cronfiles=exec('crontab -l',$output);
echo "<pre>";
print_r($output);
Which outputs:
[0] => 0 0 * * * wget php -q http://www.example.com/report_send.php
[1] => 0 0 * * * wget php -q http://www.example.com/event_reminder.php
[2] => 0 0 * * * wget php -q http://www.example.com/user_reminder.php
[3] => * * * * * wget php -q http://www.example.com/cleardata.php
Now I want to delete or remove a single cron job from my server through command. For example I want to remove cron job "0 0 * * * wget php -q http://www.example.com/event_reminder.php
" from server.
I tried crontab -r
command which removes all cron job from my server but i want to remove specific cron job.
Can you please help me for solution?
Solution 1:
-
To add a job to crontab:
(crontab -u mobman -l ; echo "*/5 * * * * perl /home/mobman/test.pl") | crontab -u mobman -
-
To remove a job from crontab:
crontab -u mobman -l | grep -v 'perl /home/mobman/test.pl' | crontab -u mobman -
-
Remove everything from crontab:
crontab -r
Nothing is tricky: -
is STDOUT in Linux!
Solution 2:
From a root prompt type
crontab -e
You can now edit the file and remove the line you want remove. You can also use this to edit crontab for users if you have the prompt for that user.
By the way: I prefer to add cronjobs to /etc/crontab
. Seems a bit more flexible to me.