- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: rsh and return code
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-02-2005 04:53 AM
08-02-2005 04:53 AM
rsh and return code
Someone posted ssh and return code and did not get much replies. I'm looking for rsh and return code when between Servers.
Does anyone know how to trap rsh return code? For example, on server A, rsh to server B and run command X (which run non-zero on error or when ran directly on Server B). I would like to trap the return code of command X when rshed from Server A. Currently rsh -l username ServerB command
always return 0
The long way to this would be to trap the return code to a file when running command X on server B, then run a rcp to grab that file from server A. Any ideas?
Thanks in advance for your time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2005 05:43 AM
08-02-2005 05:43 AM
Re: rsh and return code
For example:
rsh remotehost -n cat /tmp/file || echo $?
Shouldn't be too hard to capture the code that is returned.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2005 06:16 AM
08-02-2005 06:16 AM
Re: rsh and return code
rsh remotehost 'cat /tmp/file;echo $?'
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2005 06:50 AM
08-02-2005 06:50 AM
Re: rsh and return code
"rsh -l username ServerB /home/username/bin/programX"; echo$?
It will always return 0 because the rsh will run successfully.
in programX, I have codes to check for running of a backup program on ServerB. If backup is success, 0 is returned, but if failure, 99 is returned. If programX is ran on ServerB when backup failed, echo$? gives 99, but when ran with rsh, echo$? gives 0. How does return code is propagated via rsh ?
I tried with -n still did not work. Please advise.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2005 06:56 AM
08-02-2005 06:56 AM
Re: rsh and return code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2005 07:20 AM
08-02-2005 07:20 AM
Re: rsh and return code
I don't think that double quotes are the issue.
rsh -l username ServerB /home/username/programX; echo $?
returns 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2005 07:34 AM
08-02-2005 07:34 AM
Re: rsh and return code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2005 07:42 AM
08-02-2005 07:42 AM
Re: rsh and return code
Enclosing the command in single quotes will guarantee the echo is run remotely.
If I do:
remsh hostname 'cat blah';echo $?
the result is:
cat: Cannot open blah: No such file or directory
0
However, if I do:
remsh hostname 'cat blah;echo $?'
the result is:
cat: Cannot open blah: No such file or directory
2
Sorry to keep on the quotes but I can't think of what else would cause your return code to always be 0.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2005 08:19 AM
08-02-2005 08:19 AM
Re: rsh and return code
You got something there with the single quote:
remsh hostname 'cat blah;echo $?'
the result is:
cat: Cannot open blah: No such file or directory
2
But how to do something like below:
remsh hostname 'cat blah; result=$?;export result'
if [ $result -eq 2 ]
then
pageout
fi
Currently [ $result -eq 2 ] is failing because the result variable is not being returned to the shell. Any more insights? I'll assign points. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2005 12:25 AM
08-03-2005 12:25 AM
Re: rsh and return code
result=$(remsh hostname 'cat blah 2>/dev/null; result=$?')
if [ $result -eq 2 ]
then
pageout
fi
The 2>/dev/null makes it so any error messages are not captured and the $result variable will get just the return code number.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2005 01:35 AM
08-03-2005 01:35 AM
Re: rsh and return code
result=$(remsh hostname 'cat /tmp/blah 2>/dev/null; result=$?')
if [ $result -eq 2 ]
then
pageout
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2005 01:44 AM
08-03-2005 01:44 AM
Re: rsh and return code
Something like this should work:
result=$(remsh hostname 'cat /tmp/blah 2>/dev/null; echo $?')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2005 01:45 AM
08-03-2005 01:45 AM
Re: rsh and return code
result=$(remsh hostname 'cat /tmp/blah 2>/dev/null;echo $?')
I had copied your code and forgot to change that to an echo statement on the end.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2005 01:48 AM
08-03-2005 01:48 AM
Re: rsh and return code
result=$(remsh hostname 'cat /tmp/blah 2>/dev/null; result=$?')
if [ $result -eq 2 ]
then
pageout
fi
Will just return remsh return code and not the return code of cat command which you excuted on remote host. Do it as follows.
remsh hostname -l user_name 'cat xyz 2>/dev/null;echo $? > /tmp/status' ## Put the return status in a file
result=$(remsh hostname 'cat /tmp/status')
if [ $result -eq 2 ]
then
pageout
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2005 01:52 AM
08-03-2005 01:52 AM
Re: rsh and return code
I've tested it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2005 01:55 AM
08-03-2005 01:55 AM