Single line command to add/edit/delete crontab entry

To add a new entry in the crontab

#  crontab -l | sed ‘$a* * * * * /yourjob’ | crontab -

The above line will work only if there is an existing entry(any job entry) in the crontab. If there is no entry in the crontab then use the following line.

# echo "* * * * * /yourjob" | crontab -

To delete a entry from the crontab

#  crontab -l | grep -v  yourjob | crontab -

To edit a old entry in the crontab

#  crontab -l | grep -v  yourjob | sed ‘$a* * * * * /yourjob’ | crontab -

Advertisements