- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Need help with ssh to multiple hosts with pipe
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
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
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
тАО11-28-2012 10:44 PM
тАО11-28-2012 10:44 PM
Hi!
I have the following command which is NOT working, the way I want it to.
The intention is to ssh to a list of servers from an admin box and issue a command against a list of PID and find out the name of the PID.
for i in `cat /tmp/list`; do echo "-------------------$i----------------" ; ssh $i "lsof |grep db|grep EST|awk '{print $2}'|sort|uniq | while read i ;do ps -ef|grep $i;done " ; done
Please help!
Thanks,
Allan.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-28-2012 10:59 PM
тАО11-28-2012 10:59 PM
Re: Need help with ssh to multiple hosts with pipe
>which is NOT working, the way I want it to.
How is it failing?
for i in $(< /tmp/list); do
echo "-------------------$i----------------"
ssh $i "lsof | grep db | grep EST| awk '{print $2}' | sort | uniq | while read i ; do ps -ef | grep $i; done"
done
I can think of one thing. The "grep $i" is expanded from the outer for loop variable. Better to use different descriptive names and also quote the remote variable: (And don't put it all on one line. :-) Test it first though.
for node in $(< /tmp/list); do
echo "-------------------$node----------------"
ssh $node "lsof | grep db | grep EST | awk '{print $2}' | sort -u |
while read file; do
ps -ef | grep \$file
done"
done
- Tags:
- quoting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-28-2012 11:44 PM
тАО11-28-2012 11:44 PM
Re: Need help with ssh to multiple hosts with pipe
Invalid null command.
while: Expression Syntax.
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
done: Command not found.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-28-2012 11:45 PM
тАО11-28-2012 11:45 PM
Re: Need help with ssh to multiple hosts with pipe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-29-2012 12:11 AM - edited тАО11-29-2012 12:37 AM
тАО11-29-2012 12:11 AM - edited тАО11-29-2012 12:37 AM
Re: Need help with ssh to multiple hosts with pipe
>but I am getting: Invalid null command. while: Expression Syntax.
Ah, one more "$" to quote:
awk '{print \$2}' | sort -u |
>Is there a way to make it work using xargs instead of while?
Why bother? Use vector methods:
ssh $node "lsof | grep db | grep EST | awk '{print $2}' | sort -u > /var/tmp/fflist.\$\$;
ps -ef | grep -f /var/tmp/fflist.\$\$; rm -f /var/tmp/fflist.\$\$"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-29-2012 12:39 AM
тАО11-29-2012 12:39 AM
Re: Need help with ssh to multiple hosts with pipe
The other boxes have t-csh.
- Tags:
- scummy C shell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-29-2012 12:41 AM
тАО11-29-2012 12:41 AM
Re: Need help with ssh to multiple hosts with pipe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-29-2012 03:52 AM
тАО11-29-2012 03:52 AM
Re: Need help with ssh to multiple hosts with pipe
>The other boxes have t-csh.
Any reason you are using a real shell and trying to talk to machines with scummy C shell? ;-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-29-2012 10:22 AM
тАО11-29-2012 10:22 AM
Re: Need help with ssh to multiple hosts with pipe
while: Expression Syntax.
bash: line 1: 1: command not found
also, #1 is also not working as expected.
Is there room for xargs?
Thanks,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-29-2012 10:33 AM
тАО11-29-2012 10:33 AM
Re: Need help with ssh to multiple hosts with pipe
>I tried #2 and getting - also, #1 is also not working as expected.
Unfortunately I no longer know exactly what you have, please provide examples.
>Is there room for xargs?
Have you tried my vector method with grep -f? No loops there, just an extra temp file to clean up.