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

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-15-2017   -   Original Discussion by baluchen
baluchen's Unix or Linux Image
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; 07-15-2017 at 04:38 AM.. Reason: changed ICODE to CODE tags.
Sponsored Links
    #2  
Old Unix and Linux 07-15-2017   -   Original Discussion by baluchen
RavinderSingh13's Unix or Linux Image
RavinderSingh13 RavinderSingh13 is offline Forum Advisor  
Registered User
 
Join Date: May 2013
Last Activity: 23 January 2018, 2:59 AM EST
Location: Chennai
Posts: 2,689
Thanks: 594
Thanked 1,278 Times in 1,149 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; 07-15-2017 at 02:40 AM..
The Following User Says Thank You to RavinderSingh13 For This Useful Post:
baluchen (07-15-2017)
Sponsored Links
    #3  
Old Unix and Linux 07-15-2017   -   Original Discussion by baluchen
RudiC's Unix or Linux Image
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 23 January 2018, 8:56 AM EST
Location: Aachen, Germany
Posts: 11,980
Thanks: 356
Thanked 3,692 Times in 3,390 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; 07-15-2017 at 04:48 AM..
    #4  
Old Unix and Linux 07-15-2017   -   Original Discussion by baluchen
baluchen's Unix or Linux Image
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
Closed

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 09:18 AM
Exit a shell script Phuti Shell Programming and Scripting 2 04-24-2013 09:18 AM
exit shell from a script kopper Shell Programming and Scripting 1 09-09-2010 10:25 PM
How to grep sql error in shell script and exit the script? allinshell99 Shell Programming and Scripting 2 05-27-2010 10:06 PM
exit a shell script!! sami98 Shell Programming and Scripting 4 03-27-2007 05:55 AM



All times are GMT -4. The time now is 09:57 AM.