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 <[email protected]>
I don't run "desktop environments"; I run useful applications

Reply via email to