execute command over ssh connection

LStrike

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?

roaima

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Execute command on successful SSH connection

From Java

How to execute a remote command over ssh with arguments?

From Dev

execute remote command over ssh strange behaviour

From Dev

SSH to Server, Execute Command, and Maintain Connection

From Dev

SSH to Server, Execute Command, and Maintain Connection

From Dev

Jsch - Sending command over SSH connection

From Dev

Jsch - Sending command over SSH connection

From Dev

Unknown cipher type error on trying execute remote command over ssh

From Dev

Upload file over ssh and execute command on the remote machine

From Dev

How to execute a command over ssh and store the value in a variable

From Dev

How to execute a command through SSH and keep the connection open?

From Dev

Execute FOR loop over ssh

From Dev

Sequelize connection over ssh

From Dev

SSH: execute sudo command

From Dev

Python: How to execute more than 1 command over SSH without loggin in every command

From Dev

Reverse SCP over SSH connection

From Dev

How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?

From Dev

Cannot execute commands after logging in to server over SSH when IP is generated by linux command

From Dev

How do i execute sudo command over ssh in node JS.?

From Dev

Open putty ssh connection over SOCKS5 proxy via command line

From Java

Run ssh and immediately execute command

From Dev

ssh: execute a command before login

From Dev

ssh change user and execute command

From Dev

ssh - execute complex remote command

From Dev

Different output of command over ssh

From Dev

Ssh and run command upon connection

From Dev

Running ssh command and keeping connection

From Dev

Ssh and run command upon connection

From Dev

Execute script over SSH and get output?

Related Related

  1. 1

    Execute command on successful SSH connection

  2. 2

    How to execute a remote command over ssh with arguments?

  3. 3

    execute remote command over ssh strange behaviour

  4. 4

    SSH to Server, Execute Command, and Maintain Connection

  5. 5

    SSH to Server, Execute Command, and Maintain Connection

  6. 6

    Jsch - Sending command over SSH connection

  7. 7

    Jsch - Sending command over SSH connection

  8. 8

    Unknown cipher type error on trying execute remote command over ssh

  9. 9

    Upload file over ssh and execute command on the remote machine

  10. 10

    How to execute a command over ssh and store the value in a variable

  11. 11

    How to execute a command through SSH and keep the connection open?

  12. 12

    Execute FOR loop over ssh

  13. 13

    Sequelize connection over ssh

  14. 14

    SSH: execute sudo command

  15. 15

    Python: How to execute more than 1 command over SSH without loggin in every command

  16. 16

    Reverse SCP over SSH connection

  17. 17

    How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?

  18. 18

    Cannot execute commands after logging in to server over SSH when IP is generated by linux command

  19. 19

    How do i execute sudo command over ssh in node JS.?

  20. 20

    Open putty ssh connection over SOCKS5 proxy via command line

  21. 21

    Run ssh and immediately execute command

  22. 22

    ssh: execute a command before login

  23. 23

    ssh change user and execute command

  24. 24

    ssh - execute complex remote command

  25. 25

    Different output of command over ssh

  26. 26

    Ssh and run command upon connection

  27. 27

    Running ssh command and keeping connection

  28. 28

    Ssh and run command upon connection

  29. 29

    Execute script over SSH and get output?

HotTag

Archive