* [gentoo-user] cron - once a month during week days
@ 2015-02-05 19:19 Joseph
2015-02-05 19:35 ` Florian Gamböck
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Joseph @ 2015-02-05 19:19 UTC (permalink / raw
To: gentoo-user
I have a cron tab entry:
8 12 1-7 * 1 rsync ...
I was under impression that it will run once a month on Monday but it seems to be running every day, why?
--
Joseph
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [gentoo-user] cron - once a month during week days
2015-02-05 19:19 [gentoo-user] cron - once a month during week days Joseph
@ 2015-02-05 19:35 ` Florian Gamböck
2015-02-05 19:43 ` Alan McKinnon
2015-02-06 18:42 ` Walter Dnes
2 siblings, 0 replies; 9+ messages in thread
From: Florian Gamböck @ 2015-02-05 19:35 UTC (permalink / raw
To: gentoo-user
Hi Joseph!
Am 05.02.2015 um 20:19 schrieb Joseph:
> I have a cron tab entry:
> 8 12 1-7 * 1 rsync ...
From `man 5 crontab`:
Note: The day of a command's execution can be specified by two fields —
day of month, and day of week. If both fields are restricted (ie,
aren't *), the command will be run when _either_ field matches the
current time. For example, ``30 4 1,15 * 5'' would cause a command to
be run at 4:30 am on the 1st and 15th of each month, plus every Friday.
That means, in your case, that your rsync will run every day from the
first to the seventh of each month, plus every Monday.
Greetings
--Flo
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [gentoo-user] cron - once a month during week days
2015-02-05 19:19 [gentoo-user] cron - once a month during week days Joseph
2015-02-05 19:35 ` Florian Gamböck
@ 2015-02-05 19:43 ` Alan McKinnon
2015-02-05 20:05 ` [gentoo-user] " James
2015-02-05 20:49 ` [gentoo-user] " Rich Freeman
2015-02-06 18:42 ` Walter Dnes
2 siblings, 2 replies; 9+ messages in thread
From: Alan McKinnon @ 2015-02-05 19:43 UTC (permalink / raw
To: gentoo-user
On 05/02/2015 21:19, Joseph wrote:
> I have a cron tab entry:
> 8 12 1-7 * 1 rsync ...
>
> I was under impression that it will run once a month on Monday but it
> seems to be running every day, why?
>
As Florian explained, crontab syntax gets weird when you use fields 3 and 5.
Basically, what you want to do cannot be done in a plain crontab. You
might be able to leverage anacron to accomplish what you want.
Otherwise, you must write a wrapper script that runs daily or on Mondays
and checks a flag file that it creates and only run once in a given month
--
Alan McKinnon
alan.mckinnon@gmail.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* [gentoo-user] Re: cron - once a month during week days
2015-02-05 19:43 ` Alan McKinnon
@ 2015-02-05 20:05 ` James
2015-02-05 20:49 ` [gentoo-user] " Rich Freeman
1 sibling, 0 replies; 9+ messages in thread
From: James @ 2015-02-05 20:05 UTC (permalink / raw
To: gentoo-user
Alan McKinnon <alan.mckinnon <at> gmail.com> writes:
> Basically, what you want to do cannot be done in a plain crontab. You
> might be able to leverage anacron to accomplish what you want.
Here is a link some options, including a brief intro to anacron.
http://wiki.gentoo.org/wiki/Cron#cronie
hth,
James
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [gentoo-user] cron - once a month during week days
2015-02-05 19:43 ` Alan McKinnon
2015-02-05 20:05 ` [gentoo-user] " James
@ 2015-02-05 20:49 ` Rich Freeman
2015-02-06 8:12 ` Alan McKinnon
1 sibling, 1 reply; 9+ messages in thread
From: Rich Freeman @ 2015-02-05 20:49 UTC (permalink / raw
To: gentoo-user
On Thu, Feb 5, 2015 at 2:43 PM, Alan McKinnon <alan.mckinnon@gmail.com> wrote:
>>
>> I was under impression that it will run once a month on Monday but it
>> seems to be running every day, why?
>>
>
> Basically, what you want to do cannot be done in a plain crontab. You
> might be able to leverage anacron to accomplish what you want.
>
[Timer]
OnCalendar=Mon *-*-1,2,3,4,5,6,7 12:08:00
(ducks!)
--
Rich
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [gentoo-user] cron - once a month during week days
2015-02-05 20:49 ` [gentoo-user] " Rich Freeman
@ 2015-02-06 8:12 ` Alan McKinnon
2015-02-06 23:02 ` Rich Freeman
0 siblings, 1 reply; 9+ messages in thread
From: Alan McKinnon @ 2015-02-06 8:12 UTC (permalink / raw
To: gentoo-user
On 05/02/2015 22:49, Rich Freeman wrote:
> On Thu, Feb 5, 2015 at 2:43 PM, Alan McKinnon <alan.mckinnon@gmail.com> wrote:
>>>
>>> I was under impression that it will run once a month on Monday but it
>>> seems to be running every day, why?
>>>
>>
>> Basically, what you want to do cannot be done in a plain crontab. You
>> might be able to leverage anacron to accomplish what you want.
>>
>
> [Timer]
> OnCalendar=Mon *-*-1,2,3,4,5,6,7 12:08:00
>
> (ducks!)
>
In my defense, I've never used anacron, I just have some idea of what it
can do by reading a man page here and there :-)
--
Alan McKinnon
alan.mckinnon@gmail.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [gentoo-user] cron - once a month during week days
2015-02-05 19:19 [gentoo-user] cron - once a month during week days Joseph
2015-02-05 19:35 ` Florian Gamböck
2015-02-05 19:43 ` Alan McKinnon
@ 2015-02-06 18:42 ` Walter Dnes
2015-02-06 22:57 ` Neil Bothwick
2 siblings, 1 reply; 9+ messages in thread
From: Walter Dnes @ 2015-02-06 18:42 UTC (permalink / raw
To: gentoo-user
On Thu, Feb 05, 2015 at 12:19:13PM -0700, Joseph wrote
> I have a cron tab entry:
> 8 12 1-7 * 1 rsync ...
>
> I was under impression that it will run once a month on Monday but
> it seems to be running every day, why?
Here's a possible workaround; have the script run every Monday, but
also have the script itself check for the date and execute the real
stuff only if date <= 7, like so...
#!/bin/bash
xdate=`date +d`
if [ "10#${xdate}" -le 7 ]; then
do_whatever
fi
Note a booby trap here. `date +d` returns a 2-digit number, padded
with a leading zero if necessary. 01 through 07 are usually interpreted
as octal 01 through octal 07. 08 and 09 are invalid octal numbers, and
will cause bash to throw errors. The leading "10#" forces the following
number to be interpreted as base 10, leading zeros notwithstanding. E.g.
[d531][waltdnes][~] echo $(( 09 ))
bash: 09: value too great for base (error token is "09")
[d531][waltdnes][~] echo $(( 10#09 ))
9
For additional fun...
[d531][waltdnes][~] echo $(( 031 ))
25
[d531][waltdnes][~] echo $(( 10#031 ))
31
Or as the old joke goes...
Q: Why do geeks confuse halloween and christmas?
A: Because Oct 31 == Dec 25
--
Walter Dnes <waltdnes@waltdnes.org>
I don't run "desktop environments"; I run useful applications
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [gentoo-user] cron - once a month during week days
2015-02-06 18:42 ` Walter Dnes
@ 2015-02-06 22:57 ` Neil Bothwick
0 siblings, 0 replies; 9+ messages in thread
From: Neil Bothwick @ 2015-02-06 22:57 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 499 bytes --]
On Fri, 6 Feb 2015 13:42:45 -0500, Walter Dnes wrote:
> #!/bin/bash
> xdate=`date +d`
> if [ "10#${xdate}" -le 7 ]; then
> do_whatever
> fi
>
> Note a booby trap here. `date +d` returns a 2-digit number, padded
> with a leading zero if necessary.
Use "date +%e", which uses a space instead of a zero to pad single digit
dates.
--
Neil Bothwick
The horizon of many people is a circle with a radius of zero. They call
this their point of view.
-- Albert Einstein
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [gentoo-user] cron - once a month during week days
2015-02-06 8:12 ` Alan McKinnon
@ 2015-02-06 23:02 ` Rich Freeman
0 siblings, 0 replies; 9+ messages in thread
From: Rich Freeman @ 2015-02-06 23:02 UTC (permalink / raw
To: gentoo-user
On Fri, Feb 6, 2015 at 3:12 AM, Alan McKinnon <alan.mckinnon@gmail.com> wrote:
> On 05/02/2015 22:49, Rich Freeman wrote:
>> On Thu, Feb 5, 2015 at 2:43 PM, Alan McKinnon <alan.mckinnon@gmail.com> wrote:
>>>>
>>>> I was under impression that it will run once a month on Monday but it
>>>> seems to be running every day, why?
>>>>
>>>
>>> Basically, what you want to do cannot be done in a plain crontab. You
>>> might be able to leverage anacron to accomplish what you want.
>>>
>>
>> [Timer]
>> OnCalendar=Mon *-*-1,2,3,4,5,6,7 12:08:00
>>
>> (ducks!)
>>
>
>
> In my defense, I've never used anacron, I just have some idea of what it
> can do by reading a man page here and there :-)
>
Also in your defense - that wasn't anacron, but a systemd timer unit. :)
--
Rich
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-02-06 23:02 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-05 19:19 [gentoo-user] cron - once a month during week days Joseph
2015-02-05 19:35 ` Florian Gamböck
2015-02-05 19:43 ` Alan McKinnon
2015-02-05 20:05 ` [gentoo-user] " James
2015-02-05 20:49 ` [gentoo-user] " Rich Freeman
2015-02-06 8:12 ` Alan McKinnon
2015-02-06 23:02 ` Rich Freeman
2015-02-06 18:42 ` Walter Dnes
2015-02-06 22:57 ` Neil Bothwick
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox