Re: [gentoo-user] cron - once a month during week days

2015-02-06 Thread Rich Freeman
On Fri, Feb 6, 2015 at 3:12 AM, Alan McKinnon  wrote:
> On 05/02/2015 22:49, Rich Freeman wrote:
>> On Thu, Feb 5, 2015 at 2:43 PM, Alan McKinnon  
>> 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



Re: [gentoo-user] cron - once a month during week days

2015-02-06 Thread Neil Bothwick
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



pgpnWWtJlMGmL.pgp
Description: OpenPGP digital signature


Re: [gentoo-user] cron - once a month during week days

2015-02-06 Thread Walter Dnes
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 
I don't run "desktop environments"; I run useful applications



Re: [gentoo-user] cron - once a month during week days

2015-02-06 Thread Alan McKinnon
On 05/02/2015 22:49, Rich Freeman wrote:
> On Thu, Feb 5, 2015 at 2:43 PM, Alan McKinnon  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.mckin...@gmail.com




Re: [gentoo-user] cron - once a month during week days

2015-02-05 Thread Rich Freeman
On Thu, Feb 5, 2015 at 2:43 PM, Alan McKinnon  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



Re: [gentoo-user] cron - once a month during week days

2015-02-05 Thread Alan McKinnon
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.mckin...@gmail.com




Re: [gentoo-user] cron - once a month during week days

2015-02-05 Thread Florian Gamböck

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



[gentoo-user] cron - once a month during week days

2015-02-05 Thread Joseph

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