in reply to Execute on conditional check

if you are going to call some shell-script at certain moments every day, better to hand this task to cron.

1 1 * * *  /your/first/script and 2 1 * * *  /your/second/script are crontab entries which will run these two scripts every day at 01:01:00 and 01:02:00</c> respectively.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: Execute on conditional check
by Anonymous Monk on Jun 20, 2010 at 14:38 UTC
    Unfortunately, requirement is not to use it in a cron.:-( So need to do it in a script
    flag=0 time=$(date +"%H:%M:%S") echo $time while : do while : do if [ $(date +"%H:%M:%S") = '07:32:00' ] then echo "1st loop" break fi break done while : do if [ $(date +"%H:%M:%S") = '07:32:30' ] then echo "2nd loop" break fi break done done
    if condition is satisfied, it keeps printing out 1st loop. How to come out of the loop,if condition is satisfied.

      It seems to me that your shop does not allow cron for a reason. Could it be that they have a standard tool/package for scheduling of this type? Perhaps, something like UC4, TWS (Tivoli Workload Scheduler, AKA: Maestro), AutoSys, Control-M, CA-7, etc.

      These are very powerful tools; you might be better served looking into what your shop uses and working with the necessary team(s) to implement that way.

      This looks very much like a shell script. Shell scripts are not Perl. Please rewrite your shell script as a Perl script or ask your question elsewhere.

        I am sorry.
        while () { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime t +ime; $time_val="$hour:$min:$sec"; while ($time_val == "08:28:00") { print "1st loop\n"; } while ($time_val == "08:28:30") { print "2nd loop\n"; } }
        What is the problem in this script. I am writing the while loop recursivley, so that even for the next day it will execute checking on the condition.
        But now this code doesn't work.
        When the first condition is true, then it should print "1st loop" and execute the second while loop