Showing results for 
Search instead for 
Do you mean 

kshquery

Frequent Advisor

kshquery

[ Edited ]

 

Hello team

 

I'm writing a korn shell code on a unix box to check to see stale partition in all volume groups, my commands are correct but I'm just having problem running the loop correctly, basically first I just want to run a command which will start a sync process in the back ground, and then I just want to run a loop to check to see how many stale partitions are still left and keep runnign the loop until there are 0 stale partition? I also want to record time.

 

below is my snippet, can you please correct my loop so it works, commands are find I've tested them and they work as expected. I think I'm not incrementing it properly and also my do/done are not closed properly ?

 

#!/usr/bin/ksh
set -x
Logfile=/tmp/time_recording.log
TMOUT=60

# Start looping here to check stale partitions after migration
echo "Looping to check stale partitions, sync operation and time recording will start now on $(date)">>${Logfile}



                cc=0
                if [ ${cc} -le ${TMOUT} ]; then
                for vg in `lsvg -o|grep -v rootvg` ; do
                echo "starting sync process for $vg">>${Logfile}
                echo "nohup syncvg -v $vg &">>${Logfile} # This command start sync process in the BG.
                done
                fi

                typeset -i kk=0
                for VG in `lsvg -o|grep -v rootvg` ; do
                count=`lsvg $VG | grep STALE | awk '{ print $NF }'` # this filters stale pps OK


                while [ $count -gt 0 ] ; do # Trying to run a loop to check stale partitions here
                echo "There are still $count stale PPs in the $VG vgs--please wait for sync to complete">> ${Logfile}
                (( kk = kk + 1 )) # Perhaps not incrementing it correctly ?
                done # not closing it properly somewhere ?
                done

                if [ $? -eq 0 ]; then
echo "Sync operation has completed successfully for $vg and time recording has finished on $(date)">> ${Logfile}
fi

 

Thanks in advance

 

 

P.S. This thread has been moved from HP-UX>General to HP-UX > languages. -HP Forum Moderator

5 REPLIES
Acclaimed Contributor Acclaimed Contributor

Re: ksh query

The first thing you should do is to have a consistent indentation style of 3 space or so.  And indent blocks in if/then/else, while and for.  Then we can read your program.

   while [ $count -gt 0 ] ; do # Trying to run a loop to check stale partitions here
      echo "There are still $count stale PPs in the $VG vgs--please wait for sync to complete">> ${Logfile}
      (( kk = kk + 1 )) # Perhaps not incrementing it correctly ?

   done # not closing it properly somewhere?

 

This loop will not stop since you don't change $count nor do you compare with $kk.

 

Frequent Advisor

Re: ksh query

Thanks Dennis for quick response, much appreciate it, i need to get this going soon, so apprecaite it, below is my simple snippet which works fine but I just want to add my sync command their first

 

#!/bin/ksh

logfile=/tmp/log

 

# Where should I add my sync command ie "some_command" and then continue the loop to test out stale pps ?

and I'd like to put start and end date to a log file so we know how long it took ? Please assist

 

below snippet works like a charm but need to add above before i start the loop ?

 

while true
do
for vg in `lsvg -o|grep -v rootvg` ; do
count=`lsvg $vg | grep STALE | awk '{ print $NF }'`
if [ $count -ge 1 ] ; then
echo "There are $count stale PPs in the $vg VG"
fi
done
done

Frequent Advisor

Re: ksh query

also im checking for the existence of 0 stale pps obviously, so it should come out of the loop if it has found 0 stale pp's and exit the program with the time stamp simple ?
Acclaimed Contributor Acclaimed Contributor

Re: ksh query

(( sync_pass = 0 ))

while : true; do

   (( total_count = 0 ))
   for vg in $(lsvg -o | grep -v rootvg); do
      count=$(lsvg $vg | awk '/STALE/ { print $NF }')
      if [ $count -ge 1 ] ; then
         echo "There are $count stale PPs in the $vg VG"

         (( sync_pass += 1 ))

         echo "starting sync: $(date) (pass: $sync_pass)" >> $logfile

         sync_something

         echo "ending sync:   $(date) (pass: $sync_pass)" >> $logfile

         (( total_count += count ))
      fi
   done

   if (( total_count == 0 )); then

      break  # no stale PPs

   fi
done

 

This should stop if it found no stale PP on one pass after checking on each VG.

Is this right?        if [ $count -ge 1 ] ; then

Highlighted
Frequent Advisor

Re: ksh query

Thanks Dennis, really appreciate ur knowledge sharing it has always helped me.

 

And you you are spot-on, once it has gone through the each vg and found 0 stale partition we want it to break the program.

 

I just tested the snippet you have kindly sent, it's working like a charm, thanks so much for your prompt help.


I'm always stuck in do/while done and can't just close them properly ?

 

but i will post you if the snippet has any hiccups, I think it works now as expected.

 

Keep well and talk to you soon