Message from discussion
Script help...
Received: by 10.68.213.68 with SMTP id nq4mr11119231pbc.2.1329179029207;
Mon, 13 Feb 2012 16:23:49 -0800 (PST)
Path: wr5ni21973pbc.0!nntp.google.com!news2.google.com!postnews.google.com!m24g2000yqb.googlegroups.com!not-for-mail
From: DennisW <dennistwilliam...@gmail.com>
Newsgroups: gnu.bash
Subject: Re: Script help...
Date: Mon, 13 Feb 2012 16:23:41 -0800 (PST)
Organization: http://groups.google.com
Lines: 61
Message-ID: <2ce21a67-ac91-47f9-97ce-176aa96f0075@m24g2000yqb.googlegroups.com>
References: <c5184d4a-686f-4ee8-9128-33c18556d388@f30g2000yqh.googlegroups.com>
NNTP-Posting-Host: 70.140.104.143
Mime-Version: 1.0
X-Trace: posting.google.com 1329179025 32491 127.0.0.1 (14 Feb 2012 00:23:45 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 14 Feb 2012 00:23:45 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: m24g2000yqb.googlegroups.com; posting-host=70.140.104.143; posting-account=gg-dGwkAAADOQbAA-67pcwsEXmKIxkYs
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.11 (KHTML, like
Gecko) Chrome/17.0.963.46 Safari/535.11,gzip(gfe)
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
On Feb 13, 3:21=A0pm, HB <herbert.burnsw...@gmail.com> wrote:
> Hi All,
>
> I apologize up front as I posted this request in the BashScripts.org
> group thinking it was this group (this group has much more
> participation).
>
> I have a simple shell script to run a check on the 2nd Tuesday of
> every month which I thought worked pretty well. =A0However, it appears
> that it did not work for this given month and I'd like to see if
> anyone has any suggestions as to how it can be fixed. =A0Here is the
> code:
>
> today=3D`/bin/date +%d | cut -d"0" -f2`
> tue=3D`cal | awk {'print $3'} | xargs | /usr/bin/cut -d" " =A0-f3`
>
> if [ "$today" -ne "$tue" ] ; then
>
> =A0 =A0 =A0 =A0exit 1
>
> else
>
> =A0 =A0 =A0run check here...
>
> fi
>
> exit 0
>
> So, the line:
>
> cal | awk {'print $3'} | xargs | /usr/bin/cut -d" " =A0-f3
>
> is not working as the awk pipe skips the blank lines:
>
> cal | awk {'print $3'}
>
> Tu
> 3
> 7
> 14
> 21
> 28
>
> which puts '3' into the awk line and causes '7' to be the 2nd Tuesday
> which it is not.
>
> I hope I have not confused you all too much. =A0Is there anyway to fix
> this issue to allow it to work as intended?
>
> Thanks in advance,
>
> Herb
read -r dow dom < <(date '+%w %e')
if ((dow =3D=3D 2 && dom >=3D 11 && dom <=3D 17))
then
echo "It's the second Tuesday."
fi
11 and 17 assume you mean the second Tuesday rather that the Tuesday
in the second week.