Executing a script in remote machine through ssh

How to execute a script in remote machine through ssh
I have a script test.sh which does some backup activity in remote machine. Wanted to keep backup also in remote machine.
ssh -l username <remote machine> "commands to be exceuted as ; separted"
but how to put the script in the place of commands to be exceuted as ; separted

Hi sanvel,
When you are using ssh to execute commands in remote machine, the commands which you are using is in the remote machine, not your local machine.
So, if you put a shell script's name in the place of commands to be executed, it won't work, because this is your local script.
If you must run this script in remote machine.

Firstly use

scp sample.sh user@hostname:/tmp

Then

ssh -l user hostname /tmp/sample.sh

Hope could help you

You can pass the local script via stdin to the interpreter on the remote host.
Example bash script:

ssh -l username remotehost /bin/bash < test.sh
2 Likes

tried with the below:

#!/bin/ksh
ssh -l username@hostname << EOT
cd /tmp
touch testfile
EOT

i dont want to move mn script to remote machine.

shows as

Pseudo-terminal will not be allocated because stdin is not a terminal.
Password:

=======================

1 Create one script on remote machine that does the required job.
2 Do this from local machine

ssh -q <remote_server> <path_to_script> 

MadeInGermany suggested:

ssh -l username remotehost /bin/bash < test.sh

You left out the shell to be used to execute your script. Try:

ssh -l username@hostname /bin/ksh <<EOT
cd /tmp
touch testfile
EOT

or:

ssh -l username@hostname /bin/ksh -c "cd /tmp;touch testfile"