AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
#Power
#Operatingsystems
#Servers
 View Only
  • 1.  wait_for function

    Posted 01/23/12 05:30 AM

    Originally posted by: drewpyke


    Hi there,
    I'm trying to create a function on AIX. It works on Linux.
    In other words - I can't get it working for KSH.

    wait_for() {
    res=0
    while [ ! $res -gt 0 ]
    do
    res=$(tail -5 "$START_LOG" | fgrep -c "$1")
    sleep 5
    done
    }

    Apologies if this is the wrong forum... please direct me to another if appropriate. However, any help gratefully received!

    Thanks, Andy.
    #AIX-Forum


  • 2.  Re: wait_for function

    Posted 01/23/12 05:49 AM

    Originally posted by: tony.evans


    Can you tell us why it doesn't work - beats trying to work that out for ourselves before we try and fix it.

    On Linux, do you run it under bash? Are you running it under bash or ksh on AIX?
    #AIX-Forum


  • 3.  Re: wait_for function

    Posted 01/23/12 05:59 AM

    Originally posted by: drewpyke


    Yes, on Linux I am running under bash. With AIX I'm running under ksh.

    What I'm trying to do is run a process that outputs to a file (e.g. status.log). When it gets to a certain point in that process, it says 'Server is RUNNING'.
    So this wait_for function is supposed to take the parameter of 'Server is RUNNING' then keep looping until it finds that string in status.log.

    If I run "tail -5 status.log | fgrep -c “Server is RUNNING″" then I get a return on 1. So I believe it is either the while loop not exiting correctly or the $ substitutes not doing what I think they should be.

    Cheers, Andy.
    #AIX-Forum


  • 4.  Re: wait_for function

    Posted 01/23/12 06:21 AM

    Originally posted by: tony.evans


    Does it work under bash on AIX (/usr/bin/bash)? If it does, can you just use that instead of ksh?

    Or try ksh93 (/usr/bin/ksh93), although there are significant differences between all 3.
    #AIX-Forum


  • 5.  Re: wait_for function

    Posted 01/23/12 03:08 PM

    Originally posted by: awojo


    Worked for me:

    #!/usr/bin/ksh
    START_LOG=log

    wait_for() {
    res=0
    while ! $res -gt 0
    do
    res=$(tail -5 "$START_LOG" | fgrep -c "$1")
    sleep 5
    done
    }

    wait_for zzz

    ./test.ksh

    Just sat there.. then I vi'd the log file and added a zzz at the end and then script found it and finished the loop and exited.
    #AIX-Forum