- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shellscripting remoteexecution
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
09-13-2001 06:01 AM
09-13-2001 06:01 AM
Can anyone tell me how to get the remote commands exit code for use on the localhost ?
Thanks in advance,
Lothar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2001 06:06 AM
09-13-2001 06:06 AM
Re: Shellscripting remoteexecution
You could do something like
remsh remotehost -l remote id -n "ls ; echo \$?"
This would return the output of ls and return 0 if succeeded and 1 if failed
-HTH
Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2001 06:13 AM
09-13-2001 06:13 AM
SolutionThe remsh exit code of 0 only means that the script was able to be launched. The exit status of the remote command is not returned. There is a workaround I have used for a long time.
REM_ERR_FILE=/var/tmp/x${$}.err
remsh remote_host my_command $REM_ERR_FILE
LOCAL_STAT=$?
$LOCAL_STAT only tells us about the success of remsh itself
Now my_coomand on the remote host can get the
value of $REM_ERR_FILE; any status values you are interested in can be written to that file by your script on the remote host.
When the remsh command finishes you can then
REM_STAT=`remsh remote_host cat ${REM_ERR_FILE}`
to capture the remote commands status. (You should then issue a final remsh to remove the $REM_ERR_FILE.)
It's a little complicated but it does work. Since we generate a process id dependent file fane on the local host, you don't have to worry about filename collision when multiple instances are running. This method also leaves stdderr and stdout for their normal use.
Hopes this gets you started, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2001 06:24 AM
09-13-2001 06:24 AM
Re: Shellscripting remoteexecution
A small shell function:
function remcall
{
host=$1; shift
remsh $host "$*; echo \"EXITCODE \$?\"" |
awk ' $1 == "EXITCODE" && NF == 2 { exit $2 }
1'
return $?
}
would return with the same exit code as the remote command. (Of course there must be no output on STDOUT which interfers with the EXITCODE output line).
Klaus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2001 06:32 AM
09-13-2001 06:32 AM
Re: Shellscripting remoteexecution
Clay, im very glad about your fast and great asnwers ever and ever!
I will tell the remote command a remotefile for writing its exitcode. Then in an other remotecommand I'll read stout of something like "cat remotefile"
Lothar ;-))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2001 06:35 AM
09-13-2001 06:35 AM
Re: Shellscripting remoteexecution
If i had
remsh remotehost -l remoteid -n command; echo $?
then it would return the exit code of whether the remsh executed or not but my command was
remsh remotehost -l remoteid -n "command ; echo \$?"
so for example if i do this as a regular user (this is supposed to fail)
remsh remotehost -l remoteid -n "strings /etc/lvmtab ; echo \$?"
it comes back with
/etc/lvmtab: Permission denied
1
(Now this is the expected output )
I believe the key is to use the "-n" option and "command ; echo \$?" which gives the exit code of the command rather then the exit code of the remsh.
Lothar, to find out what -n does check the man page for remsh.
-Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2001 06:43 AM
09-13-2001 06:43 AM
Re: Shellscripting remoteexecution
thanks,but the point is, that I can not use STDOUT and STDERR for getting the exitcode in this command because they are used otherwise even on the local host.
In this case it would be the easiest to use several remotecommands.
Lothar :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2001 06:45 AM
09-13-2001 06:45 AM
Re: Shellscripting remoteexecution
I agree that Clay's approach is perhaps the soundest. *However*, Ramesh's method (with the escaped return value) *does* work *IF*, as
Klaus points out, there is no other output.
Try this test:
# rexec servername -n "grep me /tmp/nofile;echo \$?"
The 'grep' returns <2> for a "nofile" condition but the return code is intermixed with "grep: can't open".
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2001 06:54 AM
09-13-2001 06:54 AM
Re: Shellscripting remoteexecution
Thanks guys,
i missed the point that you could not use the STDIO or STDERR. in which case the option is to redirect the exitcode to a file like Clay pointed out.
Once again thanks Clay/James/Lothar.
-Ramesh