- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: remote run program
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
07-22-2009 07:56 PM
07-22-2009 07:56 PM
remote run program
#cat /etc/passwd | awk -F: '{ print $1}'
root
bin
daemon
adm
lp
sync
shutdown
halt
But if I try to run it at remote server , i tried ssh root@remoteserver "cat /etc/passwd | awk -F: '{ print $1}'" , then the output is as below , the output format is different , can advise what is wrong , how can i use the existing script to run on remote server ? I have many program also want to run at remote server , can advise how can I make it work ? thx a lot
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 08:02 PM
07-22-2009 08:02 PM
Re: remote run program
cat /etc/passwd|cut -f 1
cut -f
where list is a list of fields assumed to be separated in the file by a delimiter character (see -d); for example, -f 1,7 copies the first and seventh field only. Lines with no field delimiters will be passed through intact (useful for table subheadings), unless -s is specified
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 08:13 PM
07-22-2009 08:13 PM
Re: remote run program
This will work
ssh root@remoteserver cat /etc/passwd | cut -f 1 -d":"
it will do the same thing as your script
thanks
Saravanan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2009 08:31 PM
07-22-2009 08:31 PM
Re: remote run program
remove the double quote it will work
Example:
ssh root@remoteserver cat /etc/passwd | awk -F: '{ print $1}'
it will work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2009 12:25 AM
07-23-2009 12:25 AM
Re: remote run program
it works , but may I ask what is the reason of it ? as I have other program has the same problem , I would like to fix by myself . thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2009 01:10 AM
07-23-2009 01:10 AM
Re: remote run program
because else $1 is interpreted because you are between double quotes.
so without \ it is the same as
cat /etc/passwd | awk -F: '{ print }'
so \$1 is necessary.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2009 02:22 AM
07-23-2009 02:22 AM
Re: remote run program
That's the solution I found too.
I first tried to put the command in '' but the shell doesn't seem to want to nest '', even with \'.
>because else $1 is interpreted because you are between double quotes.
Yes, it is that simple.
You can also use fire to fight fire:
XX='$1'
ssh host -n "awk -F: '{ print $XX }' /etc/passwd"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2009 02:32 AM
07-23-2009 02:32 AM
Re: remote run program
depending of the shell and unix used by your local and remote user
you may need to have 3 \ in place of 1
like my old aunt said, when it doesn't work with 1 add 2 others.
but in my case 1 \ is enough.
ssh root@myremote " awk -F: '{print \$1 }'root
daemon
bin
sys
adm
uucp
lp
nuucp
hpdb
nobody
www
laurent