Script to connect to a remote server and execute scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to connect to a remote server and execute scripts
# 1  
Old 09-02-2009
Bug Script to connect to a remote server and execute scripts

Hello All

I need a script or set of commands which can establish a remote connection with another server and execute some scripts over there. Basically it has to establish the connection with the remote server as an user ,say 'testuser' and then execute the script 'testscript'. and return the output to the parent server.

Any help is highly appreciated
-Thanks
# 2  
Old 09-02-2009
SSH + Public Key Authentication. Both are very well documented in various threads and on the Web.
# 3  
Old 09-02-2009
My idea is to execute the script from say 'host 1' which can do the job of whatever said above in 'host 2' and return
# 4  
Old 09-02-2009
...plus, testscript has to be on remote server, then you can get the output. But you can't execute a local script on remote host via ssh.
# 5  
Old 09-02-2009
I'm looking for a shell/perl or even a batch of unix commands to accomplish the same
# 6  
Old 09-02-2009
You can't just say "this script will run on another host". The script has to be locally available on the other host, either by copying it there or by a mounted remote share.

As a starting point...
1.sh:
Code:
#!/usr/bin/ksh

user=$1
server=$2

echo $user
echo $server

echo 'for i in 1 2 3 4 5
do
    echo $i
done' | ssh ${user}@${server}

cat 2.sh | ssh ${user}@${server}

scp 2.sh ${user}@${server}:/tmp/. && ssh ${user}@${server} 'chmod u+x /tmp/2.sh && /tmp/2.sh'

2.sh:
Code:
for i in 1 2 3 4 5
do
    echo $i
done

Run as './1.sh <user> <server>'. This will connect to the remote server and run the same code in 3 different variants. Choose the one that fits you best.

Last edited by pludi; 09-02-2009 at 07:27 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script connect to remote server, not find files and exit only from remote server, but not from scrip

I have a script, which connecting to remote server and first checks, if the files are there by timestamp. If not I want the script exit without error. Below is a code TARFILE=${NAME}.tar TARGZFILE=${NAME}.tar.gz ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;... (3 Replies)
Discussion started by: digioleg54
3 Replies

2. Shell Programming and Scripting

Sudo connect to a remote server and execute scripts in remote server

Hello Every one!! I am trying to write a shell script which will connect to a remote server and execute scripts which are at a certain path in the remote server. Before this I am using a sudo command to change the user. The place where I am stuck is, I am able to connect to the... (6 Replies)
Discussion started by: masubram
6 Replies

3. Shell Programming and Scripting

How to execute commands on remote server using expect script?

I need to copy python script file to around 100 servers using expect script. 1. Copy script to my user home first(/home/myhome) on each remote server 2. change permissions on copied file to 766. 3. sudo to appuser1 account on remote server. copy script file from my user home to /usr/bin/... (1 Reply)
Discussion started by: kchinnam
1 Replies

4. Shell Programming and Scripting

Execute a local script against a remote server

I am unable to run the below script against a remote server due to syntax error (then unexpected), but i am able to run it locally. Am i executing it correctly or is there any other way to execute it. ssh username@servernname ksh -s < scriptname #!/bin/ksh function record { ((end =... (5 Replies)
Discussion started by: NarayanaPrakash
5 Replies

5. Shell Programming and Scripting

Execute scripts on remote server

Hi All, I need to first of all establish a connection to remote unix server non-interactively with the help of a shell script and then connect to oracle database from that server all with this script of mine. Please suggest the best method which could be used to connect to server for executing... (1 Reply)
Discussion started by: m_kapur83
1 Replies

6. Shell Programming and Scripting

Connect to differect server and execute the script

Hello Everyody Please help me with the below problem. I have two servers names server1 and server2. From server1, i have to connect to server2 and execute a script residing on server2. How can i achieve this? (6 Replies)
Discussion started by: vasuarjula
6 Replies

7. Shell Programming and Scripting

shell script for how to connect to a remote server by using ssh

i want to connect to a remote server through ssh. i have to also provide password within that script. after connecting to the remote server i want to do some operations like grep,cd etc can u pls help me to wite a script. Thanks (1 Reply)
Discussion started by: millan
1 Replies

8. Shell Programming and Scripting

Connect to a Remote Sybase Server Through Script

Hi all, I am trying to connect to Remote Sybase database Server through shell script. I am operating on WindowsXP, connect to Unix(version SunOS: 5.8) The thing is i dont know how to connect to Sybase Server through my script file? Are there any manual pages which can guide me through the... (3 Replies)
Discussion started by: Aparna_k82
3 Replies

9. Windows & DOS: Issues & Discussions

Connect to a Remote Sybase Server Through Script.

Hi all, I am trying to connect to Remote Sybase database Server through shell script. I am operating on WindowsXP, connect to Unix(version SunOS: 5.8) The thing is i dont know how to connect to Sybase Server through my script file? Are there any manual pages which can guide me through the... (2 Replies)
Discussion started by: Aparna_k82
2 Replies
Login or Register to Ask a Question