Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Percent-signs (%) in the command, unless escaped with backslash (\),
will be changed into newline characters, and all data after the
first % will be sent to the command as standard input.
The reason why 0 1 1-7 * mon does not work.
Quote:
Commands are executed by cron(8) when the minute, hour,
and month of year fields match the current time, and when at least one of
the two day fields (day of month, or day of week) matches the current
Last edited by michaelk; 06-12-2020 at 10:09 AM.
Reason: add man cron info.
Percent-signs (%) in the command, unless escaped with backslash (\),
will be changed into newline characters, and all data after the
first % will be sent to the command as standard input.
Interesting. It seems there are significant differences between the various cron implementations.
For instance, on a system that uses "Dillon's lightweight cron daemon", the page displayed by man crontab does not contain the text above. Which cron implementation was the quote taken from?
Quote:
Originally Posted by michaelk
The reason why 0 1 1-7 * mon does not work.
Quote:
Commands are executed by cron(8) when the minute, hour,
and month of year fields match the current time, and when at least one of
the two day fields (day-of-month and or day-of-week) matches the current
That seems to indicate that the day-of-month and day-of-week fields are evaluated together as an "or" statement.
This, too, appears implementation-specific. From the man crontab page for Dillon's cron:
Quote:
If you specify both a day in the month and a day of week, it will be interpreted as the Nth such day in the month.
To further clarify/complicate/muddy things (depending on how you look at it):
I typically paste this into the tops of all my crontab files.
Code:
# Format is as follows. Six fields, with the sixth being a command to run. The first five are
# date/time related. An asterisk means run matching ANY condition
#
# * * * * * command to be executed
# - - - - -
# | | | | |
# | | | | +----- day of week (0 - 6) (Sunday=0)
# | | | +------- month (1 - 12)
# | | +--------- day of month (1 - 31)
# | +----------- hour (0 - 23)
# +------------- min (0 - 59)
...just for reference purposes. Crontabs can take fairly complicated strings, as well as regex'es, such as:
Running a script on the last Friday of the month:
The $(date +"\%m") -ne $(date -d 7days +"\%m") statement checks to see if the month today is not equal to month next week (7days from now - same day). If they are equal then current day (Friday in our case) is not the last weekday (we specified Friday) of the month. If not, it is the last Friday, so it runs your script.
No matter what date is the end of the month, the next day is always "01". The time code will kick it off, but the script will only run if tomorrows date is "01". 
You can test things on the command line with:
Code:
echo $(date +"%m") -ne $(date -d 7days +"%m")
...to play with output until you get what you want.
Your correct there are multiple versions i.e fcron, dcron (Dillon's), vixie/cronie and bcron. Without knowing what distribution/version you can not tell but Mandriva was based on Redhat which did/does use vixie/cronie. And the fact the cron log indicated a new line...
Or to be more specific, any command is legal in the 6th field. Including (in this case) [, which may or may not be a builtin, depending on the shell being used (vixie/cronie allows a user-specified shell).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.