Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2014 01:19 AM - last edited on 06-08-2014 07:37 PM by Lisa198503
06-07-2014 01:19 AM - last edited on 06-08-2014 07:37 PM by Lisa198503
kshquery
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2014 01:35 AM
06-07-2014 01:35 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2014 01:40 AM
06-07-2014 01:40 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2014 01:42 AM
06-07-2014 01:42 AM
Re: ksh query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2014 02:40 AM
06-07-2014 02:40 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2014 03:31 AM
06-07-2014 03:31 AM
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