Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Running the same remote script on multiple servers Post 302500087 by OMLEELA on Saturday 26th of February 2011 10:02:16 PM
Old 02-26-2011
Running the same remote script on multiple servers

Experts,

Im trying to remote into a server, run a script that resides on that server and capture the information displayed & store in a local file.

I struggled with this yesterday & finally that script is working now.

Now, here is a scope creep and the script that I wrote for 1 remote server now, should run on more than one server and then capture the log from the server and store it on my local desktop to be sent to mgt for further decision making.
However I tried this in more than one way, but none of the approaches that I took are yielding any results. The script when invoked individually work fine for each remote server but when I combine them, the second one fails to run.

Here is what I have so far. The highlight BOLD lines are working well now.

Please advise !

regards,
Lee
Code:
#!/bin/bash

HOST="machine1.com"
USER="admin"
PASS="pa$$word"
CMD="Ksh NewScript.sh"
VAR=$(expect -c "
spawn ssh -o StrictHostKeyChecking=no $USER@$HOST $CMD
match_max 100000
expect \"*?assword:*\"
send -- \"$PASS\r\"
send -- \"\r\"
expect eof
")
echo "==============="
echo "$VAR" >> /Users/leemc/Results.txt

sleep 5

####### W O R K S T I L L H E R E #### 
####### NOW, I WANT THIS TO CONTINUE BUT THIS ISNT WORKING #### 

HOST="machine2.com"
USER="admin2"
PASS="pa$$word2"
CMD="Ksh NewScript.sh"
VAR=$(expect -c "
spawn ssh -o StrictHostKeyChecking=no $USER@$HOST $CMD
match_max 100000
expect \"*?assword:*\"
send -- \"$PASS\r\"
send -- \"\r\"
expect eof
")
echo "==============="
echo "$VAR" >> /Users/leemc/Results.txt

sleep 5

Here is what Results.txt Looks after first write -
Code:
3434 RICHARD CB ELLIS Properties Mgt
1033 CB Gundaker Property Mgt ^M
1151 KELLER WILLIAMS Property Mgt^M

spawn ssh -o StrictHostKeyChecking=no admin@machine2.com. ./NewScript.sh^M
Password:^M
Password:

Moderator's Comments:
Mod Comment Use code tags, please...

Last edited by Scott; 02-27-2011 at 08:48 AM.. Reason: Removed excessive formatting, added code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Prevent wrong user from using shell script for multiple remote servers

Hi, I am running a shell script from a central server to multiple remote servers using the following code: application_check() { # Linux/UNIX box with ssh key based login SERVERS=`cat /tmp/server-details` # SSH User name USR="user" # create new file > /tmp/abc.log # connect... (2 Replies)
Discussion started by: mystition
2 Replies

2. UNIX for Advanced & Expert Users

Move folders from Multiple remote Servers to my local computer

I have 20 Servers (They are Windows 2003) that I remote every day using names or IP address and type in my username & Password then copy folders manually to my local computer. I'm wondering if i can just run script(s) from my local computer to do this job without using FTP(because of security... (5 Replies)
Discussion started by: idiazza
5 Replies

3. Shell Programming and Scripting

Running a script on multiple remote hosts at once

I have a script on about 15 hosts that I need to run for each host whenever I want (not crontab). Problem is, this script takes 5-10 mins to run for each host. Is there a way I can run the script in parallel for all the hosts instead of 1 at a time? Also, I'm remotely running the script on the... (3 Replies)
Discussion started by: mrskittles99
3 Replies

4. Shell Programming and Scripting

Logging in to multiple Linux servers and running the command.

Hi, I am trying to write a script to run a command on multiple linux based servers and get the o/p. I am using ssh to login. It is a celerra box and EMC NAS product. I am able login but i am not able to run nas command nas_pool -size -all the NAS server. I am getting the following error. ... (2 Replies)
Discussion started by: jpkumar10
2 Replies

5. Solaris

Remote execution of a local script on multiple servers

So I have a scriptlet called solaris_command: for i in \ server1 server2 server3 do echo $i ssh $i $1 echo "" done I then use that as a command in multiple scripts to allow for data gathering for all virtual hosts in the environment thusly: solaris_command "cat... (3 Replies)
Discussion started by: os2mac
3 Replies

6. Shell Programming and Scripting

Help with script to reach remote servers

new3=`cat /tmp/list3` for pol in "$new3" $(su - dbadmin -c "ssh $new3 '/usr//llist'"); do export policy=`echo $pol`; su - dbadmin -c "ssh $x '/usr/policycmd $policy -L |grep -i active; echo $policy'">>/tmp/listxyz;done I am having trouble with this testscript as the file list3 has two names... (1 Reply)
Discussion started by: newbie2010
1 Replies

7. Shell Programming and Scripting

Remote login and running a script on multiple servers

Hi all, I am baffled on this. Solaris Irix system.:confused: I have 4 servers all connected to one another, :b: I need to write a script line that would login on to server 1-3 ($HOST) start a script in the back ground and log off while the back ground script runs over a length of time.:eek: ... (10 Replies)
Discussion started by: weddy
10 Replies

8. Shell Programming and Scripting

Running set of commands in remote servers in shell script

Hi Wishing to all. I am very new joined in an organization as a unix system administrator. I need a help in preparing a script for a report. i have a file contains all of the linux/ubuntu servers line by line around 140 servers. vi servers.txt nh01 nh02 nh03 bh01 bh04 - - :wq (3 Replies)
Discussion started by: kumaraswamy
3 Replies

9. Shell Programming and Scripting

A webservice running on multiple servers. A patch has been deployed to them and it got successful o

A webservice running on multiple servers. A patch has been deployed to them and it got successful only in some set of servers. The change is in format of "logontime" from "dd.mm.yyyy hh24:mi:ss" to "dd/mm/yyyy hh24:mi:ss". A script has already generated the output from all servers with request and... (2 Replies)
Discussion started by: Chandan_Bose
2 Replies

10. Shell Programming and Scripting

Error running grep on Remote Servers

Im running the below command sshpass -p mypassword ssh -t user1@server2 /bin/bash -c 'echo "mypassword" | sudo -S -l; echo "$?#`grep -iE "user66|dbuser|tomcat|splunk|stash|jira|user2|docadmin" /etc/passwd`"; exit' Below is the error I get: Output: I run this command across a... (1 Reply)
Discussion started by: mohtashims
1 Replies
All times are GMT -4. The time now is 08:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy