- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Running cmds via SSH
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
08-15-2006 07:12 AM
08-15-2006 07:12 AM
I'm trying to issue the following cmd via SSH.
ssh -n hostname /usr/sbin/ioscan -funC disk | while read a b; do [[ $b = /dev/rdsk/* ]] && /usr/sbin/diskinfo $b; done | sed '/vendor/d'
This doesn't work because instead of launching the 'diskinfo' on the remote host, it's launched in the localshell, trying to diskinfo devices that might not exist on localhost!
The fix is to put the entire cmd between quotes like so:
ssh -n hostname '/usr/sbin/ioscan -funC disk | while read a b; do [[ $b = /dev/rdsk/* ]] && /usr/sbin/diskinfo $b; done | sed '/vendor/d''
HOWEVER, this is where I've got a problem. My sed part already uses single quotes, and I cannot escape them. If I remove the sed part, all works exactly has expected!
I'm trying to see how this can be accomplised *without* the need to write a script on the remote servers...
P.s.: don't question on why that cmd.. I know it's pretty useless. It's just an example of some things I'd like to do...
Regards,
Patrick
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2006 07:16 AM
08-15-2006 07:16 AM
Re: Running cmds via SSH
Use double quotes instead.
ssh -n hostname "/usr/sbin/ioscan -funC disk | while read a b; do [[ $b = /dev/rdsk/* ]] && /usr/sbin/diskinfo $b; done | sed '/vendor/d'"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2006 07:20 AM
08-15-2006 07:20 AM
Re: Running cmds via SSH
sh: Syntax error at line 1 : `/dev/rdsk/*' is not expected.
is what I get in return
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2006 07:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2006 07:21 AM
08-15-2006 07:21 AM
Re: Running cmds via SSH
Few things to look at.
Some systems don't provide environment properly, so make sure PATH and such is set.
Enclose commands in double quotes.
Example:
ssh root@hostname "ls -lrt *.iso"
For complex commands including say awk the \ for special characters will permit quotes within quotes.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2006 07:26 AM
08-15-2006 07:26 AM
Re: Running cmds via SSH
But now, what if I wanted to add an
awk '{print $2}'
?
I need to do a bunch a little scripts which collects various server information from approx. 17-18 servers.. (i.e BDFs, vgdisplay, etc.). That's why I need a bunch of theses...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2006 07:30 AM
08-15-2006 07:30 AM
Re: Running cmds via SSH
and has for having double quotes and even trying to escape my single quote won't do:
ssh -n host "/usr/sbin/ioscan -funC disk | while read a b; do [[ $b = /dev/rdsk/* ]] && /usr/sbin/diskinfo $b; done | awk \'{print $2}\'"
gives me:
sh: 2: Parameter not set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2006 07:39 AM
08-15-2006 07:39 AM
Re: Running cmds via SSH
Use double-quotes, then single-quotes, and escape special characters, such as $.
Also, I believe the error you reported in your second posting was caused by not escaping (\) the LF between lines.
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2006 07:45 AM
08-15-2006 07:45 AM
Re: Running cmds via SSH
the following worked:
ssh -n host "/usr/sbin/ioscan -funC disk | while read a b; do [[ \$b = /dev/rdsk/* ]] && /usr/sbin/diskinfo \$b; done | awk '{print \$1}'"
and so does something like:
ssh -n host "/usr/sbin/ioscan -funC disk | while read a b; do [[ \$b = /dev/rdsk/* ]] && /usr/sbin/diskinfo \$b; done | sed '/vendor/d'"
so basically, when using double quotes, it's only $ I need to escape, and not the ' single quotes.
thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2006 07:56 AM
08-15-2006 07:56 AM