Unable to run a sequence of commands using SSH

sasuke

I am unable to use a couple of sudo commands while logging in through ssh. I am using the following command but its not working properly.

ssh hypr1000.opsr.com "ot=sudo virsh list --all |grep running| awk '{print $2}' | tail -2 ;sudo virsh dominfo $ot"

This is the returned error message:

error: command 'dominfo' requires <domain> option

What should I do to make this command run successfully?

Lekensteyn

You are basically running ssh host "var=value; echo $var". The shell performs variable expansion before ssh received the command. Thus, the actual command as received by ssh becomes:

var=$value; echo 

In order to avoid the shell eating your dollar, use single quotes:

ssh host 'var=value; echo $var'

Considering your command, it looks like you are trying to use the output of one command in the last one. For that to succeed, you must make proper use of command substitution:

ssh host 'output=$(sudo virsh list --all | awk "/running/{print \$2}" | tail -2); sudo virsh dominfo $output'

Or even:

ssh host 'sudo virsh dominfo $(sudo virsh list --all | awk "/running/{print \$2}" | tail -2)'

This assumes that sudo is configured not to ask for a password, otherwise you will get an error such as:

sudo: no tty present and no askpass program specified

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Run multiple ssh commands using execl

From Dev

Is it possible to run some SSH commands using SFTP?

From Dev

Can't run git commands using SSH agent forwarding

From Dev

Run multiple commands in different SSH servers in parallel using Python Paramiko

From Dev

Can't run git commands using SSH agent forwarding

From Dev

How to run several commands using ssh and android in only one session?

From Dev

Run a sync sequence of commands in sublime plugin

From Dev

Unable to run perl script for ssh login to Windows server (using Net::SSH::Perl) from crontab

From Dev

Simple way of using Fabric or Boto to ssh into an AWS instance and run Shell commands

From Dev

Unable to kill remote commands by name through ssh

From Dev

using subprocess to ssh and execute commands

From Dev

Using root Commands with JSch (ssh)

From Dev

Continue/run commands after ssh into VM

From Dev

How to run commands on SSH server in C#?

From Dev

SSH to server, Sudo su - then run commands in bash

From Dev

Automatically run commands over SSH on many servers

From Dev

Log Commands Run Over SSH on Client Side

From Dev

SSH into secondary server and run multiple commands with putty

From Dev

How to run subshell commands over SSH?

From Dev

How to run commands in batch mode over ssh?

From Dev

How to ssh and run multiple commands wrapped in if else?

From Dev

ssh to a server, run couple of manual commands and exit

From Dev

How to automatically run commands on SSH login?

From Dev

Unable to run telnet commands on Genymotion emulator on Mac

From Dev

Unable to run svn commands on a repository version 1.7

From Dev

using watch run 2 commands

From Dev

Using powershell to run diskpart commands

From Dev

shell file opens terminal and run a sequence of commands in specific order

From Dev

shell file opens terminal and run a sequence of commands in specific order

Related Related

  1. 1

    Run multiple ssh commands using execl

  2. 2

    Is it possible to run some SSH commands using SFTP?

  3. 3

    Can't run git commands using SSH agent forwarding

  4. 4

    Run multiple commands in different SSH servers in parallel using Python Paramiko

  5. 5

    Can't run git commands using SSH agent forwarding

  6. 6

    How to run several commands using ssh and android in only one session?

  7. 7

    Run a sync sequence of commands in sublime plugin

  8. 8

    Unable to run perl script for ssh login to Windows server (using Net::SSH::Perl) from crontab

  9. 9

    Simple way of using Fabric or Boto to ssh into an AWS instance and run Shell commands

  10. 10

    Unable to kill remote commands by name through ssh

  11. 11

    using subprocess to ssh and execute commands

  12. 12

    Using root Commands with JSch (ssh)

  13. 13

    Continue/run commands after ssh into VM

  14. 14

    How to run commands on SSH server in C#?

  15. 15

    SSH to server, Sudo su - then run commands in bash

  16. 16

    Automatically run commands over SSH on many servers

  17. 17

    Log Commands Run Over SSH on Client Side

  18. 18

    SSH into secondary server and run multiple commands with putty

  19. 19

    How to run subshell commands over SSH?

  20. 20

    How to run commands in batch mode over ssh?

  21. 21

    How to ssh and run multiple commands wrapped in if else?

  22. 22

    ssh to a server, run couple of manual commands and exit

  23. 23

    How to automatically run commands on SSH login?

  24. 24

    Unable to run telnet commands on Genymotion emulator on Mac

  25. 25

    Unable to run svn commands on a repository version 1.7

  26. 26

    using watch run 2 commands

  27. 27

    Using powershell to run diskpart commands

  28. 28

    shell file opens terminal and run a sequence of commands in specific order

  29. 29

    shell file opens terminal and run a sequence of commands in specific order

HotTag

Archive