Cron scheduling question

Forum for questions and support relating to the 1.29.x releases only.
Locked
ngauruhoe
Posts: 25
Joined: Sun Jan 03, 2016 5:26 pm

Cron scheduling question

Post by ngauruhoe »

Hi, I'm trying to follow the example in the doc here: http://zoneminder.readthedocs.io/en/lat ... on-example. But not much luck so far. This is what I tried and the result:
1) Added to root crontab (sudo -s and using crontab -e):
0 22 * * 0-6 root /usr/bin/zmpkg.pl Test
cron.log shows:
CRON[3562]: (root) CMD (root /usr/bin/zmpkg.pl Test)
ZM console shows no difference, i.e. not the Test run state

2) Added to ZM (user skywalker) crontab:
0 22 * * 0-6 skywalker /usr/bin/zmpkg.pl Test
cron.log shows:
CRON[3735]: (skywalker) CMD (skywalker /usr/bin/zmpkg.pl Test)
ZM console shows no difference, i.e. not the Test run state
3) I also tried the 2nd one but with 'sudo' in front of the /usr/bin/......... No difference, no state change

Btw, Ubuntu is 15.10 and zmpkg.pl is in /usr/bin (and not in /usr/local/bin).

What can I try next? Appreciate your help!

Mike

ps. ZM run state Test exists of course.......If anyone would wonder
bbunge
Posts: 2934
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: Cron scheduling question

Post by bbunge »

My recommendation is to install Webmin if you are not a Linux command line guru. Webmin puts many tasks, including cron, into a web gui which is easy!
ngauruhoe
Posts: 25
Joined: Sun Jan 03, 2016 5:26 pm

Re: Cron scheduling question

Post by ngauruhoe »

I may, but I'dd like to learn and understand what it is that I am doing incorrectly. Any clue's?

Thank you.
ngauruhoe
Posts: 25
Joined: Sun Jan 03, 2016 5:26 pm

Re: Cron scheduling question

Post by ngauruhoe »

Also got this figured out at last. I initially followed the syntax of the cron entries already in root's crontab. The six'th field of every entry in there was the uid ('root'). So, that's what I used as well in the entries I added. But in the cronlog the resulting commands seem to start with the uid. After removing it, everything works fine. Run states are nicely changed at the specified times. See below.

Code: Select all

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --repo$
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --repo$
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --repo$
0  8    * * 1-5         /usr/bin/zmpkg.pl Weekday_Daytime
0 20    * * 1-5         /usr/bin/zmpkg.pl Weekday_Nighttime
0 8     * * 6           /usr/bin/zmpkg.pl Weekend
# 36 22 * * 0-6   /usr/bin/zmpkg.pl Test
#
I have no clue why my entries do not work with a uid and the original entries do work with it. If anyone knows......I still like to learn......
mikb
Posts: 600
Joined: Mon Mar 25, 2013 12:34 pm

Re: Cron scheduling question

Post by mikb »

On my Slackware systems, no crontab entries have a user field.

Try "man crontab" on your system and read what it says about the fields -- I've just skimmed mine and see nothing about handing off to other users, the crontab file called "root" runs the rooty things, a crontab file called "myuser" would run them as "myuser" etc. -- they are not lumped into one file. Maybe yours are?

Maybe you have a more advanced version of cron?

Or maybe you have a script/binary called "root" which runs the following arguments as root for some reason? A bit like "sudo something" :)

Try "which root" or "whereis root" to see if it coughs up a clever helper script -- I don't have one!
Baylink
Posts: 338
Joined: Sun Jun 19, 2005 3:19 am

Re: Cron scheduling question

Post by Baylink »

Crons are one of the most widely disparate -- and least well documented -- facilities amongst *nix distros.

I think the one that takes the username as a column is the 'Vixie' cron, written by Paul Vixie, late of DEC. Usually, the /etc/crontab takes the username, and the ones in /var/spool/cron/crontabs/$USERNAME don't... but what I've *never* seen is one where a single crontab has both types.
mikb
Posts: 600
Joined: Mon Mar 25, 2013 12:34 pm

Re: Cron scheduling question

Post by mikb »

Slackware: "Our crontab format is roughly similar to that used by vixiecron. " :)

So the "roughly similar" is probably where all this diverges.

I don't have an /etc/crontab (although there are /etc/cron.d - empty, and /etc/cron.[hourly/daily/monthly/weekly] which just contain scripts to directly execute, not a "crontab" fornatted file in sight.
ngauruhoe
Posts: 25
Joined: Sun Jan 03, 2016 5:26 pm

Re: Cron scheduling question

Post by ngauruhoe »

Thanks for the answers. The 'whereis root' etc. didn't show much.

Directly editing (nano /etc/crontab) or becoming root and editing through crontab -e results in editing the same, system-wide, crontab. The answer is in the header where it explains how the system-wide is different from a user crontab.

It still doesn't explain though why my entries, without the user, do work. Hard to see how a positional field may be skipped. Perhaps the logic is smart enough to figure out that something with a '/' cannot be a user name and subsequently defaults to root because it is the system-wide crontab.

Code: Select all

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. [b]These files also have username fields,
# that none of the other crontabs do.[/b]

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow [b]user[/b] command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
0  8    * * 1-5         /usr/bin/zmpkg.pl Weekday_Daytime
0 20    * * 1-5         /usr/bin/zmpkg.pl Weekday_Nighttime
0 8     * * 6           /usr/bin/zmpkg.pl Weekend
# 36 22 * * 0-6   /usr/bin/zmpkg.pl Test
#
Locked