Running script on remote server


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running script on remote server
# 1  
Old 03-19-2013
Running script on remote server

Hi All,

I need to run a ksh script on around 200 servers(consisting of AIX,LInux,HP-UX,Solaris). The script is there in the /tmp directory of all the servers. I want want to execute the script in background on the respective servers and then exit from there. I have written something like below:


for i in `cat Server_List`
do ssh -q $i "nohup ksh /tmp/script.ksh -E &"
done


But i want the for loop to execute the remote script and then exit and proceed to the next server in Server_List.

For this i wrote:


for i in `cat Server_List`;
do ssh -q $i < "ksh /tmp/script.ksh -E &; exit";
done


But i am getting errors like below:
bash: ksh /tmp/script.ksh -E &; exit: No such file or directory
bash: ksh /tmp/script.ksh -E &; exit: No such file or directory
.... .... ..... ..... ...... ......

Can someone help me in creating a script that serves my objective.
# 2  
Old 03-19-2013
Hi, in this moment I can't test this code, but try this way:

Code:
for i in `cat Server_List`
do 
	ssh -l login_name -q $i "nohup /tmp/script.ksh -E" &
done

# 3  
Old 03-19-2013
That is a useless use of cat and dangerous use of backticks.

Code:
while read SERVER
do
        ssh -q -l login_name $SERVER 'nohup ksh /tmp/script.ksh -E' &
done < serverfile

# Wait for all of them to finish
wait

# 4  
Old 03-19-2013
Try
Code:
ssh -qxn $i "ksh -c 'exec ksh /tmp/script.ksh >/dev/null 2>&1' &"
sleep 1

The -x closes X11 connection.
The -n closes stdin; stdout and stderr is closed at the remote side.
The ksh -c wrapper is to ensure that >/dev/null 2>&1 works even if login shell were a C-Shell.
The sleep 1 is best practice (allows to ^C interrupt, avoids problem with too fast socket allocation, ...)
I think nohup is not needed here.
-E option is not portable - specific to Linux/pdksh?
# 5  
Old 03-19-2013
@MadeInGermany

-E option is needed as an argument for this script. Also,since i will be running the script over ssh is the "-x" option needed?

---------- Post updated at 12:21 PM ---------- Previous update was at 12:19 PM ----------

@Corona688

SERVER is the Serverlist file is guess, then what is "serverfile"?
# 6  
Old 03-19-2013
SERVER is the name of the variable to read into, which is why $SERVER is used later.

serverlist is the server list file.

I'd actually make one change here:
Code:
ssh -n -q -l login_name $SERVER 'nohup ksh /tmp/script.ksh -E' &

# 7  
Old 03-19-2013
Also, i want to invoke the script in background on the respective servers and then exit from there and then proceed to the next server on the list, i dont want the script to wait for finishing on one server and then proceed to the next.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 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

Running a script on remote server kills my login session

Hi there, I'm trying to run a script remotely on a server in a particular directory named after hostname which already exists, my login session gets killed as soon as I run the below command. Not sure what is wrong, is there a better way to do it ? Note: I can also use nohup command to run... (14 Replies)
Discussion started by: mbak
14 Replies

3. Shell Programming and Scripting

How to Append the output of a script running in remote server to a file in local server?

Hi guys, So i am in server1 and i have to login to server 2, 3,4 and run some script there(logging script) and output its result. What i am doing is running the script in server2 and outputting it to a file in server 2 and then Scp'ing the file to server1. Similarly i am doing this for other... (5 Replies)
Discussion started by: srkmish
5 Replies

4. Shell Programming and Scripting

Running a function on a remote server via SSH in a script

I'm working on a script (mostly for practice) to simplify a task I have to do every now and then. I have a cluster with 6 servers on it, each server has a directory with a set of files called *.pid and *.mpid. Each file contains the pid of a process that may or may not be running on that server.... (3 Replies)
Discussion started by: DeCoTwc
3 Replies

5. Shell Programming and Scripting

How to stop a script running in remote server from local script

Hi, I have googled for quite some time and couldn't able to get what exactly I am looking for.. My query is "how to stop a shell script which is running inside a remote server, using a script"??? can any one give some suggestions to sort this out. (1 Reply)
Discussion started by: mannepalli
1 Replies

6. Solaris

Running command on Remote server

Hi, I have username/password for a remote server. I would like to have list of filenames and their size in a particular directory of remote server. Now Problem is - I can not use rsh command as I can not modify rhost file of remote server. Thanks in advance. Sanjay (1 Reply)
Discussion started by: sanjay1979
1 Replies

7. Shell Programming and Scripting

Running a Script in a Remote server

I am trying to write a script that would let me run a command in a remote server using ssh. scriptA: (dcm2nii is a command that only works on the other server) dcm2nii a b c scriptB: (I run this one on the current server) ssh -X otherserver /home/abc/Desktop/scriptA But when I do ... (2 Replies)
Discussion started by: ZeroGPX
2 Replies

8. Shell Programming and Scripting

Script to check running processes on remote server.

Hi, I am trying to write a script, which queries a db to get the names of processes, stores it in a file and then checks if that process is running on a remote server. However I am not getting it right, could anyone help me out. #!/bin/sh echo "select Address from Device where Cust =... (5 Replies)
Discussion started by: amitsayshii
5 Replies

9. Shell Programming and Scripting

Running a remote Server through perl script

Hello people, I am want to run a server on remote machine through perl scripting using telnet api. Now when I try to do so, the server gets started perfectly, but as soon as I close the telnet connection in the script, the server started on the remote machine suddenly goes down. I also... (0 Replies)
Discussion started by: chandrak
0 Replies

10. Shell Programming and Scripting

running a script on remote server.

I need to run a script on a remote server from my ksh script. The issue I'm having is that I need to logon to the remote server as a different user. (see the following) logged on to server 1 as adsmgr neet to log on to server 2 as odemgr run passwd_util.ksh Thanks in advance. (1 Reply)
Discussion started by: whited05
1 Replies
Login or Register to Ask a Question