Thomas_Heidrich
Thomas_Heidrich

Reputation: 3

How can I create a crontab in a Shell script

I have to automate my Crontab script and would like to insert some things in my Crontab file, I want to do that without interactive query and it should look like command:

crontab_admin.sh -add -s "15 9 * * *" -c "check_backup_include_list.sh" -u "USERNAME" -t "CRQ000000000000"

crontab_admin.sh -remove -s "15 9 * * *" -c "check_backup_include_list.sh" -u "USERNAME" -t "CRQ000000000000"

and it should look like this in crontab afterwards:

15 9 * * * $HOME/scripts/check_backup_include_list.sh

sry for my bad english

Upvotes: 0

Views: 1762

Answers (1)

Romeo Ninov
Romeo Ninov

Reputation: 7215

Its not wise to operate directly with cron file. But you can add record with script like this:

crontab -l >/tmp/c1
echo '15 9 * * * /full/path/to/scripts/check_backup_include_list.sh' >>/tmp/c1
crontab /tmp/c1

If you want to remove particular record you can do for example with something like this:

crontab -l >/tmp/c1
grep -v check_backup_include_list.sh' /tmp/c1 > /tmp/c2
crontab /tmp/c2

Upvotes: 3

Related Questions