- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- SSH script using a for loop
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
02-07-2007 10:16 PM
02-07-2007 10:16 PM
Hi I'm generating a script to collect audit information from a list of servers. I want it to run from a central server and it will use ssh to communicate.
I hope this is a simple question...maybe not. I am trying to get the firmware revision of my root disks. I can do a vgdisplay to get the disks and then I want to do a diskinfo -v for each disk and grep out the firmware. I am unsure how to script it. Is it possible to do a for loop within an ssh command.
Adam
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2007 10:25 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2007 11:42 PM
02-07-2007 11:42 PM
Re: SSH script using a for loop
$ ssh machine 'for i in 1 2; do echo $i; done'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2007 11:50 PM
02-07-2007 11:50 PM
Re: SSH script using a for loop
the way you describe it, you will have at least two options, either run a script/set of scripts on your clients (Dennis's solution)
OR
run your script on your server, but with multiple ssh connections being made.
So you would first send your vgdisplay -v, capturing the output on the server. A bit more server processing and you can then build your diskinfo script file on the server to run over ssh.
Either solution should work. You would have to evaluate multi-client maintenance versus multiple sessions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2007 12:06 AM
02-08-2007 12:06 AM
Re: SSH script using a for loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2007 12:22 AM
02-08-2007 12:22 AM
Re: SSH script using a for loop
> I am aware if this was a standard for loop without the functions I could use continue but this is not working within the function. Is it possible?
No. One solution, however, is from within your 'for' loop, call your function (subroutine). The function should return zero (0) for success or one (1) for failure. In you 'for' loop test the return and 'continue' or not:
function me
{
...
return 0 # ...or 1 if failure
}
for ...
me || continue
...
Thus, if 'me' fails, the 'continue' is exercised otherwise the remainder of the 'for' block executes.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2007 12:53 AM
02-08-2007 12:53 AM
Re: SSH script using a for loop
So only root can usually execute the diskinfo command because the disks' char devs cannot be read by others.
The same is the case for files like /etc/lvmtab .
If you don't want to relinquish permissions on these files your script must be run as root.
On the other hand permitting root logins (even via SSH) isn't a good habit for several reasons.
Usually one would login under a low priviledged maintenance account and then su to root.
Anyway, you could stuff something like this (of course better formatted) in a script on the clients, and make it root owned with setting the suid bit (another of the big Don'ts).
/usr/sbin/vgdisplay -v vg00|awk '/PV Name/{print$NF}'|sed s/dsk/rdsk/|xargs -n1 diskinfo|awk '/desc|rev/{print$NF}'
(n.b. at least one sed and awk call can be avoided by an appropiate awk block if you use awk functions like sub(), match() etc.)
E.g. executed on one of our boxes produces this:
/dev/rdsk/c2t2d0:
HPC2
/dev/rdsk/c1t2d0:
HPC2
As for the pinging, that doesn't necessarily proof if the to be contacted remote host is up or down.
We for instance, have most of our servers behind firewalls that only allow SSH connections (from our central managing host where one would run the SSH for loop) but silently drop all ICMP echo requests.
If this is not an issue for you,
then you could do as already shown by the others with some construct like
for $h in hostA hostB hostC; do
ping $h -n 1 -m 5 >/dev/null 2>&1 || continue
# do ssh stuff here
done
Btw, I cannot beleive that the FW revision of your Root VG disks change that often to not have this information stored in some more tangible table or file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2007 01:10 AM
02-08-2007 01:10 AM
Re: SSH script using a for loop
Anyway thanks all for the help