This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: SYSTEM-owned shell shortcut


On Sun, 29 Aug 2004, Hannu E K Nevalainen wrote:

> Igor wrote:
> > On Sat, 28 Aug 2004, Hannu E K Nevalainen wrote:
>
> <SNIP>
> >> Your scripting also have a problem at hour boundaries. (Launch it
> >> "imaginary" at 11:59 or 23:59).
> >
> > Yes, true.  I've looked long and in vain for a way of converting the
> > date from pure second counts (you can convert *to* the second count
> > using the "%s" GNU extension).  If anyone finds such a way, please
> > let me know.
>
> FYI: The DATE() and TIME() functions of any (ANSI) REXX interpreter has
> nice features wrt this; e.g. "Regina" is available at sf.net
> (http://regina-rexx.sourceforge.net/) and compiled OOTB in cygwin at
> version 3.0 (I've yet to try the more recent versions; current is 3.3,
> then we also have a new gcc since then).
>
> -- example --
> #!/usr/bin/rexx
>
> parse arg secs .
>
> say 'Current time:' time('n')
> say 'Adding' secs 'seconds:' time('n',(time('s')+secs)//(24*60*60),'s')
>
> /* time(ouput_format,input_time,input_time_format) */
> -- cut --
>
> > Of course, one can always use perl, but that seems a bit heavyweight
> > for such a purpose.
>
> Well, that depends on the competition... pure bash is ofcourse the least
> resource hungry; then you have these at least ;-)

FYI, my main objection to using perl is not the loading time (it's faster
to write the whole thing as a perl script, FWIW), but its availability on
many systems.  Bash (and awk) come standard as part of the Base category.
Perl doesn't.  Rexx (or Regina) most certainly doesn't.  If I made the
above a perl script, it wouldn't work on many installations.

> <SNIP>
>
> >> I've attached my "sysbash", which WFM.
> >> Who knows there might be problems with it too ;-P
> >
> > Well, not so much as a problem, just seems too complex.  Why call
> > *bash* through *cmd /c*???  Why bother with control codes?
>
> Ahh... ;-) I knew there was issues, I even found more; addition in bash
> expects OCTAL numbers if there is a leading ZERO.

Gulp.  I didn't notice that one!!!  Ugh.  Well, my script doesn't have
this problem with hours and minutes (since awk is used instead of bash),
but for the seconds, a change in the script is needed.  See below.

> This script is almost a year old and I use it only occassionally. Such
> is life.
>
> > Wouldn't something like the below script be much simpler?
> >
> > --------------------- BEGIN script ---------------------
> > #!/bin/bash
> > export CYGWIN="$CYGWIN check_case:adjust"
> > AT="`which at 2>/dev/null`"
> > [ -z "$AT" ] && echo "\"at.exe\" not found" >&2 && exit 1
> > CMD="$(cygpath -aw /bin/bash.exe) --login -i"
> > HHMM="$(echo "$(date "+%H +%M")" | awk '{printf("%02d:%02d",($2>58)?($1+1)%24:$1,($2>58)?0:($2+1))}')"
> > "$AT" "$HHMM" /interactive $CMD
> > # Countdown
> > secs=$((60 - $(date +%S))); while [ $secs -ne 0 ]; do echo -ne 'Please wait' $secs 'seconds for the shell \r'; sleep 1; secs=$(($secs - 1)); done

In light of the octal number problem, change the above line to:

secs=$((60 - 10#$(date +%S))); while [ $secs -ne 0 ]; do echo -ne 'Please wait' $secs 'seconds for the shell \r'; sleep 1; secs=$(($secs - 1)); done

> > ---------------------- END script ----------------------
>
> Looks nice, though you're "cheating" with awk ;-).

Well, as long as some program is in the Base category, using it isn't
considered cheating, IMO.

> It might also be that this has the same race issue as my script has;
> execution under certain conditions might be so slow that the deployment
> of "at" comes too late - postponing the launch 24 hours.

Very true.  A more robust script would check the output of "at" afterwards
and re-schedule the command if the race kicked in.  Ideally, it would also
check the output of "at" after the countdown is complete, and if the
command failed, notify the user of that and remove the command (instead of
leaving it for the next day).

> > Oh, and at.exe doesn't exist under Win9x normally, but there's a MSDN
> > sample that can be compiled and should work on Win9x:
> > <http://msdn.microsoft.com/library/en-us/vcsample98/html/vcsmptasksched.asp>.
>
> Ahh... Thats good to know if you're running W98.
>
> Well, nuff' for now - isn't it?

Hopefully it is. :-)
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Happiness lies in being privileged to work hard for long hours in doing
whatever you think is worth doing."  -- Dr. Jubal Harshaw

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]