Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Read exit value from Shell script

Shell Programming and Scripting


Tags
return value, shell, solved, solved ssh

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 1 Week Ago
baluchen baluchen is offline
Registered User
 
Join Date: Jul 2008
Last Activity: 15 July 2017, 9:16 AM EDT
Posts: 31
Thanks: 1
Thanked 0 Times in 0 Posts
Read exit value from Shell script

Hi all,

I have a situation to read exit value of a command (not exit code) and process further.


Code:
bash-4.2$ returnvalue=`ssh DOMAIN\\\\user1@10.7.7.68 'cmd /c "del C:\Users\user1\db_test.bak"'`
Could Not Find C:\Users\user1\db_test.bak
bash-4.2$ echo $?
0
bash-4.2$ echo $returnvalue
bash-4.2$

I intentionally made "db_test.bak" not available because i want the return value to be captured.

The expectation is the return value "Could Not Find C:\Users\user1\db_test.bak"to be assigned in a variable.

Appreciate your help

Thanks
Bala

Last edited by RudiC; 1 Week Ago at 03:38 AM.. Reason: changed ICODE to CODE tags.
Sponsored Links
    #2  
Old Unix and Linux 1 Week Ago
RavinderSingh13 RavinderSingh13 is online now Forum Advisor  
Registered User
 
Join Date: May 2013
Last Activity: 27 July 2017, 2:44 PM EDT
Location: Chennai
Posts: 2,563
Thanks: 564
Thanked 1,209 Times in 1,088 Posts
Hello baluchen,

Could you please try following and let me know if this helps you.

Code:
ssh user_name@host "commands" 2>error_output

Now above will capture the errors if any will come from commands, if you want to see them then you could run following command.

Code:
cat error_output  >&2

Let me know how it goes it then.

Thanks,
R. Singh

Last edited by RavinderSingh13; 1 Week Ago at 01:40 AM..
The Following User Says Thank You to RavinderSingh13 For This Useful Post:
baluchen (1 Week Ago)
Sponsored Links
    #3  
Old Unix and Linux 1 Week Ago
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 27 July 2017, 1:40 AM EDT
Location: Aachen, Germany
Posts: 11,066
Thanks: 284
Thanked 3,411 Times in 3,141 Posts
Try

Code:
returnvalue=`ssh DOMAIN\\\\user1@10.7.7.68 'cmd /c "del C:\Users\user1\db_test.bak"' 2>&1`

although I'm not too sure how MS handles error msgs to stderr nor how it assigns exit codes.

Last edited by RudiC; 1 Week Ago at 03:48 AM..
    #4  
Old Unix and Linux 1 Week Ago
baluchen baluchen is offline
Registered User
 
Join Date: Jul 2008
Last Activity: 15 July 2017, 9:16 AM EDT
Posts: 31
Thanks: 1
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by RavinderSingh13 View Post
Hello baluchen,

Could you please try following and let me know if this helps you.

Code:
ssh user_name@host "commands" 2>error_output

Now above will capture the errors if any will come from commands, if you want to see them then you could run following command.

Code:
cat error_output  >&2

Let me know how it goes it then.

Thanks,
R. Singh
Thank you Singh. It worked as expected.

Thank you
Bala
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Exit the shell script pracheth Shell Programming and Scripting 5 09-06-2013 08:18 AM
Exit a shell script Phuti Shell Programming and Scripting 2 04-24-2013 08:18 AM
exit shell from a script kopper Shell Programming and Scripting 1 09-09-2010 09:25 PM
How to grep sql error in shell script and exit the script? allinshell99 Shell Programming and Scripting 2 05-27-2010 09:06 PM
exit a shell script!! sami98 Shell Programming and Scripting 4 03-27-2007 04:55 AM



All times are GMT -4. The time now is 02:52 PM.