[BlueOnyx:24204] Re: help with crontab

Michael Stauber mstauber at blueonyx.it
Sun Aug 23 14:21:27 -05 2020


Hi Meaulnes,

> I want to install a shell script that runs every day with crontab.
> 
> Now I know there is some catch on BlueOnyx for doing that but I didn't
> jot it down.
> 
>
> So there *is* a crontab file but I can't edit it the normal way... can I
> just edit /etc/crontab and add my line like
> 5 4 * * * root /root/myScript.sh    # run myScript.sh every day at 04:05
> without breaking anything?
> Do I have to restart some service?
There are a couple of different ways how this can be done.

You can use "crontab -e" to create a new Root cronjob. There isn't one
already, but when you use "crontab -e" it'll fire up the VIM editor,
allows you to specify your cronjob and when you than save it, you can
see it in being present when you run "crontab -l".

Or you can put the cronjob into a file like /root/mycron and can then
run "crontab /root/mycron" to put it into effect. Likewise: Afterwards
"crontab -l" will show that cronjob as being present.

Another way is to put your cronjob into one of the existing config
directories of cron:

[root at 5209r ~]# tree -d /etc/cron*|grep -v error
/etc/cron.d
/etc/cron.daily
/etc/cron.half-hourly
/etc/cron.hourly
/etc/cron.monthly
/etc/cron.quarter-daily
/etc/cron.quarter-hourly
/etc/cron.weekly

Take a look at the scripts that are already in these directories to get
some idea. Whatever is in /etc/cron.daily gets executed once per day.

Whatever is in /etc/cron.d/ gets executed by the time configured in the
config files.

Example:

[root at 5209r ~]# cat /etc/cron.d/swatch.cron
# swatch is the system watcher
*/15 * * * *    root    /usr/sausalito/sbin/swatch.sh >/dev/null 2>&

As you can see there, /etc/cron.d/swatch.cron makes sure that
/usr/sausalito/sbin/swatch.sh gets executed every 15 minutes.

Typically when I add cronjobs, I just put a config file like this into
/etc/cron.d/, as it's the easiest and most transparent way.

When you create such a new config file, it is best to restart crond like
this: "systemct restart crond".

-- 
With best regards

Michael Stauber



More information about the Blueonyx mailing list