Can I add a cron job without editing a file? [duplicate]

I want to write a script that add a cron job to my crontab but without user intervention like editing a file using crontab -e. Is there a way to programatically manipulate the cron jobs from command line? Any suggestion on how to do that? Thanks in advance.


Solution 1:

To install a crontab:

echo "1 1  * * *  test" | crontab -

should do the trick.

NOTICE that this substitutes the whole crontab. You have to save the value it had with crontab -l if you just want to add/edit things. For example

(crontab -l && echo "1 1  * * *  test") | crontab -

will add the line to your crontab.