- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ssh remote 'if' command
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
05-27-2010 06:44 AM
05-27-2010 06:44 AM
In running remote commands via ssh I've had many successes but not with an if conditional. Can anyone make this work with ssh?
Note: Its not a password problem my authorized_keys file is up to day.
ssh -l $LOGNAME $hostname "if [[ ! -f /etc/profile ]] then
MAX="Number"
fi"
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2010 07:12 AM
05-27-2010 07:12 AM
Re: ssh remote 'if' command
You could do:
# ssh -l ${LOGNAME} ${hostname} -n "[ -f /etc/profile ] && echo 1 || echo 0" > /tmp/returned
...and then examine the value in the '/tmp/returned' file.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2010 07:54 AM
05-27-2010 07:54 AM
SolutionI think JRF is right, the problem is that the environment is not sourced.
I'd recommend merely calling a script with return value(code to send it) that does this work.
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
05-27-2010 08:20 AM
05-27-2010 08:20 AM
Re: ssh remote 'if' command
Preventing the local shell from interpolating variables is also very important in situations like this. You may need to use single quotes or escape characters to accommodate your needs.
Consider:
# ssh -l myuser myhost -n 'MAX=0;[ -f /etc/profile ] && MAX=1;echo ${MAX}' > /tmp/returned
...works to return 0 or 1 in the file on the local server.
...whereas:
# ssh -l myuser myhost -n "MAX=0;[ -f /etc/profile ] && MAX=1;echo ${MAX}" > /tmp/returned
...does not.
However, you could do:
# ssh -l myuser myhost -n "MAX=0;[ -f /etc/profile ] && MAX=1;echo \${MAX}" > /tmp/returned
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2010 09:25 AM
05-27-2010 09:25 AM
Re: ssh remote 'if' command
ssh -l $LOGNAME $hostname "if [[ ! -f /etc/profile ]] then MAX=Number; fi"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2010 03:52 AM
05-28-2010 03:52 AM
Re: ssh remote 'if' command
You need a ";" before the "then".
ssh -l $LOGNAME $hostname "if [[ ! -f /etc/profile ]]; then MAX=Number; fi"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2010 05:45 AM
05-28-2010 05:45 AM
Re: ssh remote 'if' command
I think all of you failed to take into consideration the use of the '\' character before special characters like '['. A very important syntax rule when using either ssh or remsh. Except for James, who touched on it, but I could not get James' suggestion to work either.
I will leave this open if anyone wants to continue fiddling with it.
Please trap and paste in your output so I can see the test run successes.
Thanks to you All!