I want to excecute the following command over a ssh connection:
tmpValue=$(cat /var/run/jboss-as/jboss-as-standalone8.pid) && top -b -U jboss -n 1 |grep $tmpValue |awk '{print $9}'
This command is working on my target machine.
Now I want to use this command from a different machine and execute it via ssh, so what I have done is this:
ssh jboss@myTargetServer tmpValue=$(cat /var/run/jboss-as/jboss-as-standalone8.pid) && top -b -U jboss -n 1 |grep $tmpValue |awk '{print $9}'
The result is
cat: /var/run/jboss-as/jboss-as-standalone8.pid: No such file or directory
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
Whats wrong with my call?
It might be easier to simplify the command so that you have fewer special characters on which the shell might choke:
ssh jboss@myTargetServer 'ps -p $(cat /var/run/jboss-as/jboss-as-standalone8.pid) -o %cpu= 2>/dev/null'
The trailing 2>/dev/null
throws away the error text in the event that the PID file either cannot be found or contains a stale PID.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments