1832262 Members
2972 Online
110041 Solutions
New Discussion

Re: Shell scripting

 
dhrtrth
New Member

Shell scripting

Hi i am a beginner in shell scripting,I was trying to run a script written by me using remsh command,the command looks like this
remsh -n grep "string" /etc/hosts
the string which i am looking for does not exist in the remote host,but still the exit status of the command is 0(success)..how is it possible?is there any other way to do this,kindly let me know.thanx in advance
5 REPLIES 5
Christian Gebhardt
Honored Contributor

Re: Shell scripting

Hi

exit status is 0 because it's the exit status of the remsh command and this command works fine

Try this

remsh -n "grep "string" /etc/hosts; echo \$?"

Chris
Leif Halvarsson_2
Honored Contributor

Re: Shell scripting

Hi,
The remsh commands succeds (and returns 0) this has no relation to the remote command. Have a look at man page for remsh.

Re: Shell scripting

The 0 return you are getting is the result of the remsh command (which completed successfully). If you restructure your command so that you "cat /etc/hosts" on the remote machine then pipe the result to a local grep eg:
remsh -n cat /etc/hosts | grep "string"
then $? will contain the result of the grep (as the last command in the line) not the remsh.

Hope this helps.
Stephen
Dario_1
Trusted Contributor

Re: Shell scripting

Hi

See the return value part from man page:

RETURN VALUE
If remsh fails to set up the secondary socket connection, it returns
2. If it fails in some other way, it returns 1. If it fully succeeds
in setting up a connection with remshd, it returns 0 once the remote
command has completed. Note that the return value of remsh bears no
relation to the return value of the remote command.

Regards,

DR
Tim D Fulford
Honored Contributor

Re: Shell scripting

Try

remsh -n "egrep string /etc/hosts >/dev/null 2>&1 ; echo $?"

This will return the RC from the grep... In ksh you can further refine this

RC=$(remsh -n "egrep string /etc/hosts >/dev/null 2>&1 ; echo $?")
echo $RC

Now you have the RC from the remote egrep.

Tim
-