Reputation: 51
The following command runs well when i run it localy on the dsired machine:
app_name=*some_proccess_name*
pid=`pgrep $app_name | tail -n 1`
But when i run it in the following way, from a remote pc using ssh it dosn't work:
pid=$(ssh $USER_NAME@$HOST_NAME "echo `pgrep $app_name | tail -n 1`")
The value of pid afterwards is just blank. I am not sure what's wrong (just to clarify i have tried several processes names that are all running on the target pc- that's not the problem ).
P.S when i run the command without echo, like that, i just get stuck inside the remote pc and have to use exit in order to get unstuck and return to my local pc:
pid=$(ssh tester@mir1 "`pgrep indicator-apple | tail -n 1`")
Upvotes: 0
Views: 114
Reputation: 69396
Less is more
pid=$(ssh tester@mir1 pgrep indicator-apple \| tail -n 1)
Upvotes: 3