Gentoo Archives: gentoo-user

From: Walter Dnes <waltdnes@××××××××.org>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] cron - once a month during week days
Date: Fri, 06 Feb 2015 18:42:59
Message-Id: 20150206184245.GA17119@waltdnes.org
In Reply to: [gentoo-user] cron - once a month during week days by Joseph
1 On Thu, Feb 05, 2015 at 12:19:13PM -0700, Joseph wrote
2 > I have a cron tab entry:
3 > 8 12 1-7 * 1 rsync ...
4 >
5 > I was under impression that it will run once a month on Monday but
6 > it seems to be running every day, why?
7
8 Here's a possible workaround; have the script run every Monday, but
9 also have the script itself check for the date and execute the real
10 stuff only if date <= 7, like so...
11
12 #!/bin/bash
13 xdate=`date +d`
14 if [ "10#${xdate}" -le 7 ]; then
15 do_whatever
16 fi
17
18 Note a booby trap here. `date +d` returns a 2-digit number, padded
19 with a leading zero if necessary. 01 through 07 are usually interpreted
20 as octal 01 through octal 07. 08 and 09 are invalid octal numbers, and
21 will cause bash to throw errors. The leading "10#" forces the following
22 number to be interpreted as base 10, leading zeros notwithstanding. E.g.
23
24 [d531][waltdnes][~] echo $(( 09 ))
25 bash: 09: value too great for base (error token is "09")
26 [d531][waltdnes][~] echo $(( 10#09 ))
27 9
28
29 For additional fun...
30
31 [d531][waltdnes][~] echo $(( 031 ))
32 25
33 [d531][waltdnes][~] echo $(( 10#031 ))
34 31
35
36 Or as the old joke goes...
37 Q: Why do geeks confuse halloween and christmas?
38 A: Because Oct 31 == Dec 25
39
40 --
41 Walter Dnes <waltdnes@××××××××.org>
42 I don't run "desktop environments"; I run useful applications

Replies

Subject Author
Re: [gentoo-user] cron - once a month during week days Neil Bothwick <neil@××××××××××.uk>