I found this command line is not working
ssh i01n10 "/usr/sbin/lsof -p $(pgrep -nf a.out)"
it shows the error
lsof: no process ID specified
However
ssh i01n10 "$(pgrep -nf a.out)"
correctly gives the PID
Why lsof is not seeing the PID?
I found this command line is not working
ssh i01n10 "/usr/sbin/lsof -p $(pgrep -nf a.out)"
it shows the error
lsof: no process ID specified
However
ssh i01n10 "$(pgrep -nf a.out)"
correctly gives the PID
Why lsof is not seeing the PID?
The lsof command can't see your PID because of shell expansion. That means $(pgrep -nf a.out) will be executed on your local server, not remote.
To avoid this expansion, use single quote instead of double quote.
Simple example:
$ foo=local
$ ssh debian8 "foo=remote; echo $foo"
local
$ ssh debian8 'foo=remote; echo $foo'
remote
You might have problem with your pgrep command. This is my simple test using -of instead of -nf flags (Use -af flag to see full command):
// on remote server
# sleep 200 &
[1] 27228
# exit
// on local host
$ ssh debian8 'echo $(pgrep -nf sleep)'
27244 <-- not expected pid
$ ssh debian8 'echo $(pgrep -of sleep)'
27228 <-- this one
This $() actually launches a subshell, pgrep doesn't report itself as a match but it does report its parent shell. Hence, using -n option will not give you actual pid but the pid of pgrep itself.