I'm stuck in a situation,
I run this command on node2
netstat -tlpna|grep `ps aux|grep tnslsnr|grep -v grep|awk '{print $2}'`|head -1
and it works fine and gives me this output
tcp 0 0 10.6.1.22:1521 0.0.0.0:* LISTEN 2601/tnslsnr
But when i run this command from clinet machine to node2 it gives me error.
ssh root@$(pcs status|grep oracle_LR|awk '{print $4}') 'netstat -tulpna $(ps aux|grep -v grep|grep tnslsnr'|awk '{print $2})'
After Following from @steeldiver
I added double quote around awk and it is working
ssh root@$(pcs status|grep oracle_LR|awk '{print $4}') 'netstat -tulpna|grep $(ps aux|grep tnslsnr|grep -v grep|awk "{print \$2}")'|head -1
gives me this output
tcp 0 0 xxx.xxx.xxx.xxx:1525 0.0.0.0:*
LISTEN 2601/tnslsnr
BUT
when i add this line in my script.
$echo "<pre>`ssh root@$(pcs status|grep oracle_LR|awk '{print $4}') 'netstat -tulpna|grep $(ps aux|grep tnslsnr|grep -v grep|awk "{print \$2}")'|head -1`</pre>"
and when i run it gives me this output
grep: oracle: No such file or directory
grep: 2601: No such file or directory
grep: 0.0: No such file or directory
grep: 0.0: No such file or directory
grep: 227812: No such file or directory
grep: 18536: No such file or directory
grep: ?: No such file or directory
grep: Ssl: No such file or directory
grep: Aug27: No such file or directory
grep: 6:16: No such file or directory
grep: LISTENER: No such file or directory
I have been playing around with this but nothing is working
grep
seem to say that it is getting a full line of output fromps
, and the best candidate for that isawk "{print \$2}"
: if the applied quoting is not enough, it easily becomesawk "{print }"
(because there isn't a positional parameter n. 2 in the shell running it). Maybeawk "{print \\$2}"
is enough to avoid that error. – fra-san Sep 14 '20 at 12:19