Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

crontab last day shell script

18 views
Skip to first unread message

V.Ronans

unread,
Sep 30, 2007, 6:16:12 PM9/30/07
to
Hello everyone. The other day I accidentally came across a shell script
that I cannot find again for the life of me, despite searching google
and a dozen or so other search engines...

<side note>
Why in the name of Socrates' stained toga do search engines not provide
some way to search explicitly for phrases and words with special
characters - like to search for code bits, like var1=$var2 and such - it
really is infuriating search for $cal and getting thousands of which
have nothing to do with shell, unix, scripting computers, etc. ARRGH
</side note>

The script I came across the other day which I cannot locate again,
despite all the searching and checking of history and scouring of my
cache, was a rather simple script for executing some task (the script it
self didn't specify, leaving it to be added in) on the last day of a
month and also the last day of a year. I can't remember if the script
was stand alone or is meant to be run through cron.

The script looked something like the following, which I'm attempting to
reconstruct from memory:

I think it starts with either #!/bin/sh or #!/bin/bash or so, then has
some comment text, like "this is a general purpose script"

Then there was something about getting the current date (I recall a bit
using variables like $1, $2, $3, ..)

Then something there was some assignment like:

: $(cal)
LAST_DAY_OF_MONTH="$_"

after that I recall a skeleton if-then-else sort of bit where it checks
if it's the last day of month and also if it's the last day of year
(something like if dec and last_day_of_month)


I'm not 100% sure of the exact variable names but this is all I can
remember.


The closest I've come in all my searching was this page:
http://groups.google.com/group/no.it.os.unix.linux.diverse/msg/8c5222fa7db3b122

Though I'm not sure it's based on the same script as what I originally
saw, but feels some what close.

Thanks to anyone who can help me find this again. This is really driving
me nuts.


Chris F.A. Johnson

unread,
Sep 30, 2007, 6:42:04 PM9/30/07
to
On 2007-09-30, V.Ronans wrote:
> Hello everyone. The other day I accidentally came across a shell script
> that I cannot find again for the life of me, despite searching google
> and a dozen or so other search engines...
>
><side note>
> Why in the name of Socrates' stained toga do search engines not provide
> some way to search explicitly for phrases and words with special
> characters - like to search for code bits, like var1=$var2 and such - it
> really is infuriating search for $cal and getting thousands of which
> have nothing to do with shell, unix, scripting computers, etc. ARRGH
></side note>

Add specific terms such as 'shell' or 'script'.

> The script I came across the other day which I cannot locate again,
> despite all the searching and checking of history and scouring of my
> cache, was a rather simple script for executing some task (the script it
> self didn't specify, leaving it to be added in) on the last day of a
> month and also the last day of a year. I can't remember if the script
> was stand alone or is meant to be run through cron.
>
> The script looked something like the following, which I'm attempting to
> reconstruct from memory:
>
> I think it starts with either #!/bin/sh or #!/bin/bash or so, then has
> some comment text, like "this is a general purpose script"
>
> Then there was something about getting the current date (I recall a bit
> using variables like $1, $2, $3, ..)
>
> Then something there was some assignment like:
>
>: $(cal)
> LAST_DAY_OF_MONTH="$_"

There is a library of shell functions for date manipulation at:
<http://cfaj.freeshell.org/shell/ssr/08-The-Dating-Game.shtml>


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence

Will Renkel

unread,
Oct 1, 2007, 8:27:26 AM10/1/07
to
v...@spamless.and.happy wrote:
>Hello everyone. The other day I accidentally came across a shell script
>that I cannot find again for the life of me, despite searching google
>and a dozen or so other search engines...
>
><side note>
>Why in the name of Socrates' stained toga do search engines not provide
>some way to search explicitly for phrases and words with special
>characters - like to search for code bits, like var1=$var2 and such - it
>really is infuriating search for $cal and getting thousands of which
>have nothing to do with shell, unix, scripting computers, etc. ARRGH
></side note>
>
>The script I came across the other day which I cannot locate again,
>despite all the searching and checking of history and scouring of my
>cache, was a rather simple script for executing some task (the script it
>self didn't specify, leaving it to be added in) on the last day of a
>month and also the last day of a year. I can't remember if the script
>was stand alone or is meant to be run through cron.
>
>The script looked something like the following, which I'm attempting to
>reconstruct from memory:
>
>I think it starts with either #!/bin/sh or #!/bin/bash or so, then has
>some comment text, like "this is a general purpose script"
>
>Then there was something about getting the current date (I recall a bit
>using variables like $1, $2, $3, ..)
>
>Then something there was some assignment like:
>
>: $(cal)
>LAST_DAY_OF_MONTH="$_"
>
>after that I recall a skeleton if-then-else sort of bit where it checks
>if it's the last day of month and also if it's the last day of year
>(something like if dec and last_day_of_month)
>
>
>I'm not 100% sure of the exact variable names but this is all I can
>remember.
>
>
>The closest I've come in all my searching was this page:
>http://groups.google.com/group/no.it.os.unix.linux.diverse/msg/8c5222fa7db3b122
>
>Though I'm not sure it's based on the same script as what I originally
>saw, but feels some what close.
>
>
>
>Thanks to anyone who can help me find this again. This is really driving
>me nuts.
>
>

try the following if you like

#/bin/ksh
_curr=`date '+%m'`
_next=`date -d '+1day' '+%m'`
if test $_curr -ne $_next
then
echo last day
else
echo NOT last day
fi
if test "`date '+%m%d'`" = '1231'
then
echo last day of year
fi

--
---------------------------------------------------------------
Will Renkel
Wheaton, Ill.

---------------------------------------------------------------

Miles

unread,
Oct 1, 2007, 11:45:45 AM10/1/07
to
> The closest I've come in all my searching was this page:http://groups.google.com/group/no.it.os.unix.linux.diverse/msg/8c5222...

>
> Though I'm not sure it's based on the same script as what I originally
> saw, but feels some what close.
>
> Thanks to anyone who can help me find this again. This is really driving
> me nuts.

Did you see this:

http://groups.google.ca/group/comp.unix.questions/browse_thread/thread/3c2c251e7082756/876e45da1c0fd0e1?hl=en&lnk=gst&q=TZ+cron&rnum=16#876e45da1c0fd0e1


It was talked about, in this group, I long time ago.

Miles

V.Ronans

unread,
Oct 1, 2007, 12:44:28 PM10/1/07
to

Thank you for you help, but that script that I had originally come
across is not there. I would really like to find that exact script. I've
done every search possible, and I know I did not imagine it. I just
happened to accidentally close the window and later on when I realized
it I just couldn't find it again. Argh.

<semi-rant>
On another side note, I am really feeling google groups' usability is
ever increasing going down the drain. Also, every time I open a thread,
half the posts are "collapsed" and I have to go through and expand them.
I hate it when someone tried to decide for me which posts are "worthy"
and which are not. Good grief. I want the old google groups back! The
old one (before the so-called "google groups beta", where I could easily
find anything I was looking for and everything just worked.)

I've noticed on various occasions that it leaves out posts I know exist
unless I put the exact group name in the groups field (i.e.,
comp.unix.shell rather than *unix* or *shell*, or comp.lang.perl.misc
instead of *perl*.) Methinks maybe this is why I'm having such a hard
time finding that post again (I'm reasonably certain it was a Usenet
post in GG I saw.)

And Google web, and other major engines, have gotten just as bad imho; I
used to be able to find things so much easier in the past, now more and
more results (more and more often at or near the top) bare absolutely no
relevance to what I'm looking for; If I search for Photoshop tutorials
or plug-ins, I end up with links to cracks, warez, etc. I'm convinced
that google, and many search engines in general, have become or are
becoming a giant cesspool of uselessness.

Too many have gone the "more flash, less substance" approach (seemingly
started by Microsoft... it's like everyone wants to copy the eye-candy
style theme of Vista, rather than provide solid useful webapps.) Too
much emphasis javascript/ajax/flash/etc. Any of which are fine and
dandy, but overall are being way over used in many sites. Some make so
much use that some browsers slow to a crawl. Even worse is when it comes
to web based ads that use flash and/or ajax.
</semi-rant>

Are there no programming/technical friendly search engine out there at
all? One would think there would some that rise above the status quo of
mediocrity?

I'm pretty sure I'd have a much easier time finding it if search engines
actually allowed search terms with programming code like $var's and even
full statements to be explicitly searched for.


Thanks again. Sorry for all my ranting but the search engine bs out
there is really truly frustrating.


Miles

unread,
Oct 1, 2007, 4:15:48 PM10/1/07
to
> >http://groups.google.ca/group/comp.unix.questions/browse_thread/threa...

I found this a while ago, and copied it. Credit is given to author:


Try this with your own time zone:
0 1 28-31 * * [[ $(TZ=EST5EDT-24 date +%d) = 1 ]] && /your/script
The logic is that every 28th to 31st of the month, it will check if
24
hours later is the 1st and run the script
Pierre Malenfant

Joachim Schmitz

unread,
Oct 2, 2007, 6:25:28 AM10/2/07
to

"Miles" <my_spam...@shaw.ca> schrieb im Newsbeitrag
news:1191269748.4...@d55g2000hsg.googlegroups.com...
Good stuff, but does not seem to work during wintertime and may not work
correctly in summertime
You'd need to substract the 24 h from _both_, the summer and the winter _GMT
offset_
for EST5EDT (which actually is EST5EDT6, isn't it?):
0 1 28-31 * * [[ $(TZ=EST-19EDT-18 date +%d) = 1 ]] && /your/script
for Central European Time this might work:
0 1 28-31 * * [[ $(TZ="CET-25CEST-26,M3.5.0,M10.5.0" date +%d) = 1 ]] &&
/your/script

At least 'TZ="CET-25CEST-26,M3.5.0,M10.5.0" date' gives me a date and time
exactly 24h ahead.

Not sure how it behaves if the switch between summer and wintertime falls in
the range of these 24 hours...

Bye, Jojo


0 new messages