Ubuntu – Add lines to cron from script

automationcronscripts

Is there a way to add lines to a user's cron via script?

I usually do it using crontab -e, but I would like to automate this task with a shell script.

Best Answer

You can echo the line in to the bottom of the current users crontab like this:

#!/bin/bash

line="* * * * * /path/to/command"
(crontab -u userhere -l; echo "$line" ) | crontab -u userhere -
Related Question