0

I have an install script that sets up a user.

Using the install script, I want to apply a cronjob that gets executed by that user (myuser):

0 4 * * * /home/myuser/script-to-run-at-4am.sh

I have found that using the following command I can edit the crontab from another user:

sudo crontab -u myuser -e

Is there an alternative command I can use that would apply my cron job from a file to the myuser crontab?

2 Answers 2

1

The simplest way to install the crontab for the particular user is (as per man)

crontab -u <username> <file_contaning_cronjobs>
0

crontab files are stored in /var/spool/cron/crontabs/ so you could create that file directly within your script with something like:

echo "0 4 * * * /home/myuser/script-to-run-at-4am.sh" > /var/spool/cron/crontabs/<username>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .