- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Need to run a loop as per the value in the paramet...
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
Forums
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
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-25-2009 03:28 AM
06-25-2009 03:28 AM
I have created a script for checking the emulex card and the number of ports
##Checking Emulex Card
VALUE=`/sbin/lspci |grep -i -e Emulex | wc -l`
if [ $VALUE -eq 0 ]
then
echo "Emulex card is not present on $x host"
else
echo "Emulex card is present on $x host with $VALUE port"
So i want to run a loop as per the value of the VALUE parameter
Thanks
Vivek
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2009 03:44 AM
06-25-2009 03:44 AM
Re: Need to run a loop as per the value in the parameter
Not able to understand your question very clear.
if you want this loop is run till you have press ctrl+c then here it is
while true
do
##Checking Emulex Card
VALUE=`/sbin/lspci |grep -i -e Emulex | wc -l`
if [ $VALUE -eq 0 ]
then
echo "Emulex card is not present on $x host"
else
echo "Emulex card is present on $x host with $VALUE port"
sleep 3
done
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2009 03:47 AM
06-25-2009 03:47 AM
Re: Need to run a loop as per the value in the parameter
You want something like this:
# cat ./showme
#!/usr/bin/sh
VALUES=$(/sbin/lspci|grep -c -i -e Emulex)
for VALUE in $VALUES
do
if [ $VALUE -eq 0 ]; then
echo "Emulex card is not present on $x host"
else
echo "Emulex card is present on $x host with $VALUE port"
fi
done
...
Note that 'grep' can return a count so you can eliminate the extra pipe to 'wc' too.
Regards!
...JRF...
- Tags:
- for loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2009 04:04 AM
06-25-2009 04:04 AM
Re: Need to run a loop as per the value in the parameter
Sorry for the incomplete loop above.
##Checking Emulex Card
VALUE=`/sbin/lspci |grep -i -e Emulex |wc -l`
if [ $VALUE -eq 0 ]
then
echo "Emulex card is not present on $x host"
else
echo "Emulex card is present on $x host with $VALUE port"
fi
done
Okay after the execution of this loop i will get a value in VALUE parameter.
For example VALUE =4, then i want to put a for loop to execute a command 4 times on four ports
cat /sys/class/scsi_host/host0/state | grep -i ready
cat /sys/class/scsi_host/host1/state | grep -i ready
cat /sys/class/scsi_host/host2/state | grep -i ready
cat /sys/class/scsi_host/host3/state | grep -i ready
Thanks
Vivek
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2009 04:06 AM
06-25-2009 04:06 AM
Re: Need to run a loop as per the value in the parameter
> Sorry for the incomplete loop above.
Please post your complete script! It is unclear what you have now changed and what your objective is.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2009 06:13 AM
06-25-2009 06:13 AM
Re: Need to run a loop as per the value in the parameter
Will this work
for (( c=1; c<=$VALUE; c++ ))
do
cat /sys/class/scsi_host/host$c/state | grep -i ready
if [ $? -eq 0]
then
Y=$Y+1
done
fi
Thanks
Vivek
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2009 06:23 AM
06-25-2009 06:23 AM
SolutionYou have several syntax errors in your last post. The C-like 'for' loop isn't valid. Try something like this:
#!/usr/bin/sh
c=1
VALUE=4
while (( c<= ${VALUE} ))
do
/sys/class/scsi_host/host${c}/state | grep -i ready
if [ $? -eq 0 ]; then
Y=$(( $Y+1 ))
fi
c=$(( $c+1 ))
done
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2009 04:10 PM
06-25-2009 04:10 PM
Re: Need to run a loop as per the value in the parameter
You can "improve" these by removing the "$" by putting everything in (( )):
(( Y += 1 ))