1834022 Members
2437 Online
110063 Solutions
New Discussion

rsh/sshWeird Behaviour

 
SOLVED
Go to solution
Alzhy
Honored Contributor

rsh/sshWeird Behaviour

One of my users is wondering about this behaviour:

He has the following command that he tries to run via rsh or ssh from another Unix or Windows machine:

rsh unixsvr "PID=`ps -ef |grep -w SomeApp123|grep -v grep|awk '{print $2}'`;echo 'I will KILL:$PID'"

This command will eventually be what will be tied to a Java/TCL/tk Button. However, it seems the remote execution does not do what it is required to do... In the above example, it only returns "I will KILL:"

Of course, manually executing the command on the UNIX server works!!

I am stumped. Any ideas? Same behaviour for ssh...
Hakuna Matata.
2 REPLIES 2
Jdamian
Respected Contributor
Solution

Re: rsh/sshWeird Behaviour

The problem is the following

`ps -ef |grep -w SomeApp123|grep -v grep|awk '{print $2}'`

is executed on local host, not in remote host.
Before launching rsh command, the shell will run the above commands. If those prints nothing, then empty string is assigned to PID variable. Thus the real process launched will be:

rsh unisxvr "PID=''; echo 'I will KILL:$PID'"

the commands executed in remote host are:

PID=''; echo 'I will KILL:'

I suggest to substitute double quotes for single quotes, but, be aware that you have other inner single quotes.
Alzhy
Honored Contributor

Re: rsh/sshWeird Behaviour

Man.. Thanks!

I should have caught this.. the rules of evaluation of UNIX commands...

Hakuna Matata.