Executing a script in remote machine through ssh


 
Thread Tools Search this Thread
Operating Systems Linux Executing a script in remote machine through ssh
# 1  
Old 02-20-2014
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
# 2  
Old 02-20-2014
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
Code:
scp sample.sh user@hostname:/tmp

Then
Code:
ssh -l user hostname /tmp/sample.sh

Hope could help you
# 3  
Old 02-20-2014
You can pass the local script via stdin to the interpreter on the remote host.
Example bash script:
Code:
ssh -l username remotehost /bin/bash < test.sh

These 2 Users Gave Thanks to MadeInGermany For This Post:
# 4  
Old 02-26-2014
tried with the below:
Code:
#!/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:

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

Last edited by Franklin52; 02-26-2014 at 08:37 AM.. Reason: Please use code tags
# 5  
Old 06-23-2014
1 Create one script on remote machine that does the required job.
2 Do this from local machine
Code:
ssh -q <remote_server> <path_to_script>

# 6  
Old 06-23-2014
Quote:
Originally Posted by sanvel
tried with the below:
Code:
#!/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:

=======================
MadeInGermany suggested:
Code:
ssh -l username remotehost /bin/bash < test.sh

You left out the shell to be used to execute your script. Try:
Code:
ssh -l username@hostname /bin/ksh <<EOT
cd /tmp
touch testfile
EOT

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remote script via SSH not executing

I have worked on multiple scenarios to execute remote script via ssh. This problem I am not able to resolve. 2 linux hosts. Server1, Server2 on Server1 I have script called ~/scripts/start_standalone.sh XXXX cd $JBOSS_HOME NODENAME=xyz; IP_ADDR=`hostname`; MGMT_IPADDR=`hostname`;... (3 Replies)
Discussion started by: oraclermanpt
3 Replies

2. Shell Programming and Scripting

Issue in executing cat (remote ssh)

Hi, I need to ssh remotely to a machine and cat a file assign the value to a variable Script: #!/bin/bash -x value=`cat config.txt` echo "$value" ssh me@xxx.host.com "valu='cat /export/home/test.md5'; echo "$valu"" | tee Execution: $ ./x ++ cat config.txt + value='touch me' +... (5 Replies)
Discussion started by: close2jay
5 Replies

3. Red Hat

iptables applied in local machine, can't ssh remote machine after chain changed to DROP

I want to SSH to 192.168.1.15 Server from my machine, my ip was 192.168.1.99 Source Destination was UP, with IP 192.168.1.15. This is LAN Network there are 30 Machine's Connected to the network and working fine, I'm Playing around the local machine's because I need to apply the same rules in... (2 Replies)
Discussion started by: babinlonston
2 Replies

4. Shell Programming and Scripting

Executing remote commands via ssh

Hi, I'm tryin to write a script that will collect information about a remote servers, put them into variables and print them to screen. # /usr/bin/bash ls $1 > /dev/null 2>/dev/null if then echo "$1 is file" for server in $(cat $1) do # echo $server ... (5 Replies)
Discussion started by: moshesa
5 Replies

5. UNIX for Dummies Questions & Answers

how to use ssh to run shell script on a remote machine?

how to use ssh to run shell script on a remote machine? ssh user@remote sh ./script.unx i ran the above command ./script.unx HAS NOHUP COMMAND IN ITS BODY, I AM GETTING ERROR AS NOHUP NOT FOUND... i tried to run that script from remote server, its working fine do ineed to set... (6 Replies)
Discussion started by: only4satish
6 Replies

6. Shell Programming and Scripting

executing commands in remote server using ssh

I have some commands which need to be executed in remote machine. I have Linux Server from where I need to connect to Solaris server using ssh and then declare some variable over there and run some commands. I don't want to call a script which is present in Solaris server from Linux server... (7 Replies)
Discussion started by: maitree
7 Replies

7. Shell Programming and Scripting

executing command in a remote machine through ssh - shell script

Hi All, i have two machines like x and y . my requirement is i should connect to machine Y from x through ssh connection . and do some operation such as copy and move and delete files in Y machine . i tried with this code but it is doing in machine x only . and i need to exit from Y when... (1 Reply)
Discussion started by: rateeshkumar
1 Replies

8. Shell Programming and Scripting

Need help with executing multiple commands in remote machine

Hi, I work on a jumpserver and I wrote a script to transfer a file from source server to destination server. #!/bin/ksh echo "\nEnter the file name:\n" read name echo "\nSelect the Source server\n" echo "1. ODS PROD " echo "2. ODS DROPBOX" echo "3. ODS STE" echo "4. ODS STE DROPBOX"... (6 Replies)
Discussion started by: ajayakunuri
6 Replies

9. Shell Programming and Scripting

Executing a script on a remote system via SSH

Hello all, I have a relatively simple script I wrote to generate a count of errors broken down. What I would like to do is execute this script from another server so that I don't actually have to log in to the server to run the check. The script on what we'll call "Server A" is: ... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

10. Shell Programming and Scripting

Executing awk in a remote server using ssh

Hello Everybody, I'm facing a weird problem with the awk command. I'm trying to execute a simple awk command as follows, echo 1 2 | awk '{print $2}' This command prints the output 2. When i try to execute the same command in a remote server using ssh as follows, ssh user@host... (2 Replies)
Discussion started by: karthikv
2 Replies
Login or Register to Ask a Question