Can we edit crontab using a shell script

Hi,

Can some one tell me if we can configure the jobs in crontab using a shell script.

I know it can be done easily by using "crontab -e", but i just want to know whether we can add a job into the crontab using a shell script.

If it can be done, plz suggest the procedure to do it.
If it cannot be done then why(reason)?

thanks

IF you are using your own cron script file as,

crontab -f <filename>

so that installation and deinstallation will be based on that file. Else psuedo-random file will be used for this operation.

HTH.

have your script ...

a. crontab -l > $tmpfile
b. edit $tmpfile
c. crontab $tmpfile
d. rm $tmpfile

Thanks a lot...... :slight_smile: That made my life soooo easy......

Hi there,

First post on these forums can't believe it actually as I always end up browsing them... anyway...
Sorry to bounce a 4yo thread but it still has relevance.

I am actually doing exactly what is described in this thread but I have one further question and that is:

Do I then have to restart cron after making the change to have it take effect?

My guess is that since you are still using the actual crontab command, not just directly editing the cron file, then no, as I imagine it still runs the install / restart itself, as if you have just run a crontab -e?
Is this correct?

Any help would be much appreciated,

Thanks,

"crontab -e username" edits the live crontab and notifies cron of the change. There is no need to restart cron.
The technique suggested by "Just Ice" can be improved by copying the crontab twice to different names. You then have the original crontab saved if something goes wrong and a baseline file to "diff" against.

Okay, kool...

Thanks for your help :slight_smile: