in reply to Re: Execute on conditional check
in thread Execute on conditional check

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.

Replies are listed 'Best First'.
Re^3: Execute on conditional check
by dineed (Scribe) on Jun 20, 2010 at 19:35 UTC

    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.

Re^3: Execute on conditional check
by Corion (Patriarch) on Jun 20, 2010 at 15:15 UTC

    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

        If you want to write something like cron, see Schedule::Cron.

        Other than that, have you printed out your $time_val to debug it? It does not contain what you think it does. And even if it contains what you think it does, == is not the comparison operator to use for strings. See perlop for the comparison operator for strings.

        change
        while ($time_val == "08:28:00") {
        to
        if ($time_val eq "08:28:00") {
        Update: (thanks to Perlbotics)

        also change

        $time_val="$hour:$min:$sec";
        to
        $time_val=sprintf("%02d:%02d:%02d", $hour, $min ,$sec);
        Then all values smaller than 10 will be formatted with two digits.