ssh and run a ps on remote server failing
<p>I have a shell script that is trying to ssh to a remote server and get the process id of a process on the remote server. When i run the command seperately it works but from the shell script it is just spitting a blank line.
This is my input</p>

<pre><code>ps -ef|grep MYJVM
user1 10796 10531 0 11:39 ? 00:00:00 /bin/bash /opt/bin/startDataEngine Host2 77633b8f-3401-0000-0080-918586aba15f MYJVM
user1 10798 10796 0 11:39 ? 00:00:18 DataEngine Host2 77633b8f-3401-0000-0080-918586aba15f MYJVM`
</code></pre>

<p>Now when run the following command from the remote host <code>Host1</code> it works. </p>

<pre><code>/usr/bin/ssh -t -q root@host2.serv.com "ps -ef|grep -w MYJVM|grep -w '[D]ataEngine Host2\'|awk '{print \$10}'"` 
</code></pre>

<p>gives me </p>

<pre><code>`7633b8f-3401-0000-0080-918586aba15f`
</code></pre>

<p>But when I run the same command from shell script I get a blank. </p>

<pre><code>#!/bin/ksh
jvm=MYJVM
host=Host2
spid=$(ssh -t -q root@host2.serv.com "ps -ef|grep -w $jvm|grep -w '[D]ataEngine $host'|awk '{print $10}'")

echo $spid
</code></pre>

<p>I tried using double quotes for the variables <code>$jvm</code> and for the second grep <code>[D]ataEngine $host</code> but no use. </p>