Discussion:
slackware dillon's cron and crontab
Add Reply
Javier
2020-07-27 15:27:19 UTC
Reply
Permalink
I make a cron directory /etc/cron.1min with scripts to be run every
minute.

I try to run it from /etc/cron.d

echo '*/1 * * * * root /usr/bin/run-parts /etc/cron.1min' \
/etc/cron.d/cronjobs
But I get no success, I suspect because it is run with an empty
$PATH variable and /usr/bin/run-parts needs a minimum
PATH=/sbin:/bin:/usr/sbin:/usr/bin to run.

But the PATH variable is set and things run when running from crontab.

echo '*/1 * * * * /usr/bin/run-parts /etc/cron.1min' \
/var/spool/cron/crontabs/root
Why is PATH set when running from crontab and not from /etc/cron.d?

Another question? how to get the output/stderr of scripts mailed to root?

All that is not clear from the crond(1) and crontab(1) manpages.
Chris Elvidge
2020-07-27 16:55:25 UTC
Reply
Permalink
Post by Javier
I make a cron directory /etc/cron.1min with scripts to be run every
minute.
I try to run it from /etc/cron.d
echo '*/1 * * * * root /usr/bin/run-parts /etc/cron.1min' \
/etc/cron.d/cronjobs
But I get no success, I suspect because it is run with an empty
$PATH variable and /usr/bin/run-parts needs a minimum
PATH=/sbin:/bin:/usr/sbin:/usr/bin to run.
But the PATH variable is set and things run when running from crontab.
echo '*/1 * * * * /usr/bin/run-parts /etc/cron.1min' \
/var/spool/cron/crontabs/root
Why is PATH set when running from crontab and not from /etc/cron.d?
Another question? how to get the output/stderr of scripts mailed to root?
All that is not clear from the crond(1) and crontab(1) manpages.
See here:
https://www.linuxquestions.org/questions/slackware-14/cron-jobs-not-happening-4175622543/

Notably:
"Slackware uses Dillon's cron, which is not the same as Vixie cron or
cronie. When copying /etc/cron.d jobs from a distro running Vixie or
cronie, then those jobs will contain a user under which to execute the
command. Adding a user name in /etc/cron.d jobs with Dillon's cron will
cause cron to puke with exit status 127. Check the logs. Removing the
user and restarting cron should get everything back to normal.

"BTW, unlike other cron daemons, Dillon's cron does not acknowledge
dynamic changes in /etc/cron.d. Dillon's cron must be restarted for
/etc/cron.d changes to take effect."
--
Chris Elvidge, England
Javier
2020-07-27 23:56:08 UTC
Reply
Permalink
Post by Chris Elvidge
Post by Javier
I make a cron directory /etc/cron.1min with scripts to be run every
minute.
I try to run it from /etc/cron.d
echo '*/1 * * * * root /usr/bin/run-parts /etc/cron.1min' \
/etc/cron.d/cronjobs
But I get no success, I suspect because it is run with an empty
$PATH variable and /usr/bin/run-parts needs a minimum
PATH=/sbin:/bin:/usr/sbin:/usr/bin to run.
But the PATH variable is set and things run when running from crontab.
echo '*/1 * * * * /usr/bin/run-parts /etc/cron.1min' \
/var/spool/cron/crontabs/root
Why is PATH set when running from crontab and not from /etc/cron.d?
Another question? how to get the output/stderr of scripts mailed to root?
All that is not clear from the crond(1) and crontab(1) manpages.
https://www.linuxquestions.org/questions/slackware-14/cron-jobs-not-happening-4175622543/
"Slackware uses Dillon's cron, which is not the same as Vixie cron or
cronie. When copying /etc/cron.d jobs from a distro running Vixie or
cronie, then those jobs will contain a user under which to execute the
command. Adding a user name in /etc/cron.d jobs with Dillon's cron will
cause cron to puke with exit status 127. Check the logs. Removing the
user and restarting cron should get everything back to normal.
"BTW, unlike other cron daemons, Dillon's cron does not acknowledge
dynamic changes in /etc/cron.d. Dillon's cron must be restarted for
/etc/cron.d changes to take effect."
Thanks. Now I see it. So in Dillon's cron /etc/cron.d/* uses exactly
the same format as crontab.

I was getting "exit status 127 from user root root /usr/bin/run-parts"
and I was misinterpreting the error 127 as a "command not found" that
would get triggered when no $PATH is set. 127 is the error number that
you get when a command does not exist in $PATH.

$ non-existing-command; echo $?
sh: non-existing-command: command not found
127

It looks like the only way to use cron more or less portably is to
rely on crontab instead of several files in /etc/cron.d/. I think
OpenBSD does not even implement looking at files in /etc/cron.d/ and
it relies only on crontabs.
Chris Elvidge
2020-07-28 11:47:49 UTC
Reply
Permalink
Post by Javier
echo '*/1 * * * * /usr/bin/run-parts /etc/cron.1min' \
/var/spool/cron/crontabs/root
This is not the way to change a crontab. You should use 'crontab -e [-u
user]'
And lose the '/1' after the first asterisk. '*' in the column means
'every' - in this case every minute.
--
Chris Elvidge, England
Bit Twister
2020-07-27 22:05:58 UTC
Reply
Permalink
Post by Javier
I make a cron directory /etc/cron.1min with scripts to be run every
minute.
I try to run it from /etc/cron.d
echo '*/1 * * * * root /usr/bin/run-parts /etc/cron.1min' \
/etc/cron.d/cronjobs
I should have documented why I always remove the files in that directory,
But as I misunderstand it, any script in that directory is executed each minute.

I think I did the same kind of thing for my system and user accounts
that you are trying to set up.
I figured it was easier to drop my jobs in local cron directories
and also let users create their own jobs without any action on my part.

The way I did it was to put the same kind of link in each of the system
cron directories. Example in daily
_daily -> /local/bin/local_cron_job

/local/bin/local_cron_job will then run
nice -n 19 run-parts --report /local/cron/$_job

Each user has their own $HOME/.cron/(hourly, daily)

And /var/cron has a user script which look just like /etc/crontab
except HOME is the user directory.

To get them to be executed, I put a link in each of the system cron
directories to my script which in turn runs the user's cron files.
Post by Javier
But I get no success,
My guess is you need just put a script or link
to do your work.
Bit Twister
2020-07-27 22:16:35 UTC
Reply
Permalink
Post by Javier
Why is PATH set when running from crontab and not from /etc/cron.d?
because /etc/crontab sets the default values for all jobs.
Post by Javier
Another question? how to get the output/stderr of scripts mailed to root?
Hmmm, I would have thought any output from system cron jobs were mailed to root.
I am running Mageia Linuxwith Vixicron and postfix is the default MTA
which has an alias file where you define who is to get root email.

I have all root email sent to me.
Javier
2020-07-28 00:53:25 UTC
Reply
Permalink
Post by Bit Twister
Post by Javier
Why is PATH set when running from crontab and not from /etc/cron.d?
because /etc/crontab sets the default values for all jobs.
There is no /etc/crontab file in Slackware 14.2. Are you confusing it with
some other linux/BSD distro?
Post by Bit Twister
Post by Javier
Another question? how to get the output/stderr of scripts mailed to root?
Hmmm, I would have thought any output from system cron jobs were mailed to root.
I am running Mageia Linuxwith Vixicron and postfix is the default MTA
which has an alias file where you define who is to get root email.
I have all root email sent to me.
Not getting mail was my fault. I forgot to run /etc/rc.d/rc.sendmail start
After running it I got a lot of mail in my root account.
Loading...