0

I would like to know how can I run shell commands in a remote machine. I tried this:

ssh prdcrm1@${server} "grep -l 'Sometthing' *"

It is working, but I want to run more commands. Do someone has an Idea?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Edmar Munhoz
  • 221
  • 1
  • 4
  • 12
  • 1
    Create a script, copy it to remote machine and then run it remotely using `ssh`. See this as an example: https://stackoverflow.com/questions/48412836/ssh-run-process-and-then-ignore-the-output/ – iamauser Feb 12 '18 at 14:49

1 Answers1

0

You can run multiple commands on remote machine like,

Run date and hostname commands:

$ ssh user@host "date && hostname"

Run a script called /scripts/backup.sh

ssh user@host '/scripts/backup.sh'

Run sudo or su command using the following syntax

ssh user@host su --session-command="/sbin/service httpd restart"
ssh -t user@host 'sudo command1 arg1 arg2' ## su syntax ##

Multi-line command with variables expansion

VAR1="Variable 1"
ssh $HOST bash -c "'
ls
pwd
if true; then
    echo $VAR1
else
    echo "False"
fi
'"

Hope these helps you.

syam
  • 799
  • 1
  • 12
  • 30