[Smaug] A quick scripting puzzle
Thomas Leavitt
thomas at thomasleavitt.org
Sat Nov 19 12:36:34 PST 2005
I did point out that "of course, I'm cheating, by using gcal, but
hey :)" ... the unspoken part is, of course, that unless you're trying
to do a cross platform script (which I suspect is a requirement here),
as a sysadmin, you're always able to download and compile another app
(or just download a binary), if it is going to let you do your job more
efficiently.
It's "GNU Cal", not "Gnome Cal", so it is somewhat "standard" in that
sense.
Thomas
On Sat, 2005-11-19 at 09:06 -0800, Peter Belew wrote:
> Among the commands various people (including myself) have
> used, 'cal' and 'colrm' are BSD in origin. 'cal' seems to be
> universal (UNIX-versal?) anyway, but apparently some solari don't
> have 'colrm'. On Linux (Fedora Core 1 on this system):
>
> HISTORY
> The colrm command appeared in 3.0BSD.
>
> Hmm ... cal in Linux has a BSD heritage, but apparently there's
> an earlier cal from AT&T:
>
> HISTORY
> A cal command appeared in Version 6 AT&T UNIX.
>
> 'colrm' does not exist on SCO UNIX 5.0.6 (deepthought.armory.com);
> the same system's 'cal' claims to be standards-compliant.
>
> My algorithm does work on deepthought, though. My favorite
> test is like
>
> for x in 1 2 3 4 5 6 7 8 9 10 11 12; do
> > LAST=`cal $x 1752 | rest-of-my-algorithm`
> > echo $x - $LAST;
> > done
>
> After which I do 'cal 1752' to compare the dates calculated with
> the whole calendar for that year (worst-case test).
>
> - Peter
>
> On 11/19/05, Anthony Ettinger <apwebdesign at yahoo.com> wrote:
> > gcal isn't standard
> >
> > --- Thomas Leavitt <thomas at thomasleavitt.org> wrote:
> >
> > > On Fri, 2005-11-18 at 08:43 -0800,
> > > smaug-request at lists.svlug.org wrote:
> > > > Message: 2
> > > > Date: Thu, 17 Nov 2005 20:26:33 -0800
> > > > From: Peter Belew <peterbe at sonic.net>
> > > > Subject: [Smaug] A quick scripting puzzle
> > > > To: SMAUG Users <smaug at lists.svlug.org>
> > > > Message-ID: <20051118042633.GA6844 at sonic.net>
> > > > Content-Type: text/plain; charset=us-ascii
> > > >
> > > > For amusement, create a 1-line sh or bash command
> > > which will set
> > > > a shell variable $LASTSUNDAY to the date (2-digit
> > > day) of the last
> > > > Sunday in the current month.
> > > >
> > > > Like
> > > >
> > > > LASTSUNDAY=`some_shell_stuff`
> > > >
> > > > Use only standard Unix utilities such as 'cat' or
> > > 'head' or 'date'.
> > > >
> > > > The command shouldn't take longer than an
> > > 80-character line.
> > > >
> > > > (I did this myself for creating a cron job which
> > > sends out email
> > > > announcing a meeting on the last sunday of a
> > > month).
> > > >
> > > > :)
> > > >
> > > > Peter
> > > >
> > >
> > > Here's my entry... I'm pretty sure, somewhere within
> > > the byzantine array
> > > of options available in gcal, there's a way to
> > > directly produce this...
> > > but I couldn't find it. However, this works, no
> > > matter whether there are
> > > four or five Sundays in a month.
> > >
> > > LASTSUNDAY=`gcal -i -s1|tail -n1|sed "s/[
> > > ]*$//"|rev|cut -b-2|rev`
> > >
> > > I'm not sure how this works, but you could probably
> > > cheat more, by
> > > feeding gcal instructions to use some of these
> > > commands from a file...
> > >
> > > and of course, I'm cheating, by using gcal, but hey.
> > > :)
> > >
> > > Thomas
> > >
> > >
> > >
> > > _______________________________________________
> > > Smaug mailing list
> > > Smaug at lists.svlug.org
> > > http://lists.svlug.org/lists/listinfo/smaug
> > > Smaug home page: http://www.scruz.org/
> > >
> >
> >
> > Anthony Ettinger
> > ph: (408) 656-2473
> > web: http://www.apwebdesign.com
> >
> > _______________________________________________
> > Smaug mailing list
> > Smaug at lists.svlug.org
> > http://lists.svlug.org/lists/listinfo/smaug
> > Smaug home page: http://www.scruz.org/
> >
> >
More information about the Smaug
mailing list