- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- error handling remsh/ssh with script's
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
Discussions
Discussions
Forums
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
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
тАО04-19-2011 03:49 AM
тАО04-19-2011 03:49 AM
how it is the best way to handle error codes with command "remsh/ssh" ?
example :
- i have 2 scripts "main.sh", "sub.sh"
- "main.sh" starts with remsh "sub.sh"
- i want handle the errors of "sub.sh" and also i want to get output's of "sub.sh"
main.sh
remsh server "/tmp/sub.sh /not-found"
sub.sh
if [ ! -d $1 ]
then
echo "dir: $1 not found";exit 1
fi
exit 0
i tried several versions, i think this is the best ?
# tee and parse a temporary logfile
remsh server -n '( /tmp/sub.sh /not-found; echo "RETURN: $?" )' 2>&1 | tee /tmp/error_log.log
# return code in last character
rc=$( sed -n '$s/.*\(.\)$/\1/p' /tmp/error_log.log )
when i use
rc=`remsh server -n '(/tmp/sub.sh /not-found; echo $?)' `
i can't get the output with "\n" , and a variable has also a limit of 512 bytes ?
regards
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2011 04:39 AM
тАО04-19-2011 04:39 AM
SolutionFor simple cases (and here I'm going to use 'ssh' in lieu of 'remsh'), you can do:
# ssh -n server /home/billa/sub.sh
# RC=$?
# [ ${RC} = 0 ] echo "ok" || echo "bad"
If you want to capture output from the remotely run process you can do so into a file on either the local or the remote host.
# ssh -n server /home/billa/sub.sh > /home/billa/local.log
...or if you quote:
# ssh -n server /home/billa/sub.sh ">" /var/tmp/billa_remote.log
In either case you have the ability to capture the return code as first shown.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2011 12:42 AM
тАО04-20-2011 12:42 AM
Re: error handling remsh/ssh with script's
>I can't get the output with "\n"
You should be able to find the last line with the exit status:
echo "$rc" | tail -1
>a variable has also a limit of 512 bytes?
No, you can have very long strings.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2011 10:21 PM
тАО04-20-2011 10:21 PM
Re: error handling remsh/ssh with script's
can you please tell me, what is the limit of a shell variable ?
the problem of remsh/ssh is to capture the two
errors of remsh/ssh command:
first : error of remsh
second : error of remote command
a also to get an output of the error.
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2011 11:01 PM
тАО04-20-2011 11:01 PM
Re: error handling remsh/ssh with script's
Limited to heap space, I was able to get about 400 Mb:
sizeof(var): 209715200
./itrc_big_var.sh[48]: no space
>second: error of remote command
You did this by that "echo $?" on the remote side.