From: Keith Thompson on
underh20 <underh20.scubadiving(a)gmail.com> writes:
[...]
> Please critique my program below. I'd like to get feedback from you
> experts out there :-)
> Thanks, Bill
>
>
> < body of /usr/bin/script>

It's not really called "/usr/bin/script", is it? There's a standard
command called "script", and it typically lives in /usr/bin.

> #!/bin/sh
>
> LAST_SUNDAY=`cal | cut -c1-2|grep -v "^$"|tail -1`

The above didn't work on my system because the output of "cal"
includes leading and trailing blanks:

$ cal | cat -A
June 2010 $
Su Mo Tu We Th Fr Sa$
1 2 3 4 5$
6 7 8 9 10 11 12$
13 14 15 16 17 18 19$
20 21 22 23 24 25 26$
27 28 29 30 $
$
$ cal | cut -c1-2 | cat -A
$
Su$
$
6$
13$
20$
27$
$

Rather than grep -v "^$", try grep '[0-9]' to grab just lines containing
digits:

LAST_SUNDAY=`cal | cut -c1-2 | grep '[0-9]' | tail -1`

> DAY=`date +%d`
> if [$LAST_SUNDAY = $DAY]

You need spaces around the square brackets:

if [ $LAST_SUNDAY = $DAY ]

> then
> #
> # <body of codes to be executed>
> #
> exit 0
> else
> echo "EXIT!! Today is not last Sunday of month"
> fi

Suggestion: Try running code before you post it.

--
Keith Thompson (The_Other_Keith) kst-u(a)mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"