Getting one script to run on multiple boxes


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Getting one script to run on multiple boxes
# 8  
Old 03-17-2006
For once, not a typow Smilie ! The 'b' variable will hold all of the data after the first field (the server name) on each line - e.g. if you used .hosts then it would hold the userid, if you created a specific file then you could have comments or other text after the server name. Without another variable the whole line would be assigned to the 'host' variable.

hope that makes sense

cheers
# 9  
Old 03-17-2006
thestevew,

I created a ksh script that contains the 'while read' loop you described above, and added "echo $host" lines just inside the 'do' and 'done'. I also created a 'listofhostsfile' containing the names of 6 remote boxes.

If I comment out the rcp and rsh commands, the script simply echoes the name of each remote box twice, just as expected. When I uncomment the rcp and rsh lines, the loop only executes for the first remote box. Both 'echo' lines execute. For some reason, the 'while' loop thinks it is finished after the first pass through the rsh/rcp commands.

The same behavior occurs if I 'cat' the hostfile and pipe it into the 'while' loop.
If I do not use the hostfile, but hard-code the box names into a 'for' loop (Ice's script), things work fine.

Any ideas why this would happen? I have verified that the variable 'host' is not used in the script called by rsh. (I'm actually using a variable called 'whost'.) Not sure if this is relevent, but this "wrapper" script is ksh and the script executed by the rsh is "borrowed and modified" csh code that sources its local environment (ie: source /usr/blah/.cshrc).

I appreciate your help!

Last edited by bschnair; 03-18-2006 at 05:26 AM..
# 10  
Old 03-20-2006
One thing I've seen upset rsh in the past is terminal i/o - not unreasonable as there is no terminal connected. Are you sure that the script being run on the remote box isn't expecting keyboard input (you can do rsh -n ... to prevent the remote shell from reading from standard input) you might also append to the rsh command ">LogfileName.log 2>&1" (without the quotes) to send any output to a log file (or to /dev/null).
You might also look at adding some logging to the script being run on the remote box - is it failing or doing something unexpected?

hope this helps
# 11  
Old 03-20-2006
As I needed this script to function a couple of days ago, I aborted the "read from external file" concept and hard-coded the box names into a 'for' loop (per Just_Ice's original concept). It worked fine. (Thanks, Ice!)

Every 2-3 months or so I will need to change the list of server names. This would be easy and convenient by using an external file of box names, but honestly, it's just as easy and convenient to edit the script we've been discussing. Either way, it's a quick 'vi' edit on a file.

After my script was working, a coworker supplied a suggestion. I haven't tried it yet, but I thought I'd supply it here for comments:

Instead of hard-coded host names (ex: for host in server1 server2 server3), use an external file and this...

for host in `cat listofhostsfile`

Seems reasonable...
# 12  
Old 03-20-2006
try using a variable name for your list file ... the example below lets you use a different listfile from the command line but uses a default listfile if an argument is not set ... good for testing purposes or for one-offs ... enjoy!
Code:
#! /bin/ksh

listfile=$1
if [ ! -f $listfile ]
then
     listfile=/dir/listfile
fi

for host in `< $listfile`
do
    rcp -p /dir/script $host:/dir/script
    rsh $host "/dir/script"
    rcp -p $host:/dir/script/outfile /outdir/outfile.$host
done

exit 0

BTW, "cat listfile" and "< listfile" does the same thing in sh and ksh (and other shells) but the 2nd form is more efficient since it uses the shell's redirection properties instead of using an external program to read the contents of the file ... Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Run script on multiple files

Hi Guys, I've been having a look around to try and understand how i can do the below however havent come across anything that will work. Basically I have a parser script that I need to run across all files in a certain directory, I can do this one my by one on comand line however I... (1 Reply)
Discussion started by: mutley2202
1 Replies

2. Shell Programming and Scripting

Run a script on multiple servers

I need to run a script on a bunch of remote servers. how can this be done without ssh into each individual server and run it its under /sbin/script.sh on each server (1 Reply)
Discussion started by: tdubb123
1 Replies

3. Shell Programming and Scripting

Need a script to scp a file to multiple boxes

Hello All, I am new to scripting and I am trying to write a script which can scp a file from one box to multiple boxes. I am thinking to do like this. 1) create a file with list of all server names 2)write a script which will pick up each server line by line from server list and copy it to... (1 Reply)
Discussion started by: sintilash
1 Replies

4. Shell Programming and Scripting

Shell script to login into multiple linux boxes

I have requirement to login into a multiple linux boxes by running the shell script in a single linux box and to find the count of files in a specific folder in each box and log them in a log file in the box where i m runnning the script. Box names will be stored in a text file host.txt. Please... (2 Replies)
Discussion started by: Mani2512
2 Replies

5. Shell Programming and Scripting

Script to run php script on multiple website domains

Good Day, I have multiple websites on a domain. I am looking for a loop structure that can run each site script. egdomain1/test.php domainx/test.php so on, currently I copy and paste a list of commands but that skips certain commands. Some help would be greatly appreciated. Sergio (3 Replies)
Discussion started by: SergioP
3 Replies

6. Shell Programming and Scripting

Automated ssh to multiple boxes

I have a script that will ssh to several different servers, perform a command, display the output, and exit. It works well, but I have to enter my password for each server. That gets a little cumbersome when you have a couple dozen servers. Anyone out there know how to automate this so that I only... (2 Replies)
Discussion started by: fedexer
2 Replies

7. UNIX for Dummies Questions & Answers

Virtualbox OSE on multiple boxes

I have Virtualbox OSE installed on my laptop and soon on my lap top. My question is if I were to make a virtual os on an external hard drive on my laptop, can i make a settings to use the same vdi on my desktop and have it show the same screen, not at the same time. sorry, its late here and I... (0 Replies)
Discussion started by: Texasone
0 Replies

8. Shell Programming and Scripting

I need a Script to rsh multiple hp boxes and shutdown

Hello I'm serving on a ship that has frequent power issues. Currently if we loose power we need to rush around to multiple UNIX machines and login to Sysadmin and power down each machine before we loose our ups. If sysadmin is asleep or not in the space we have some real problems. I would like to... (2 Replies)
Discussion started by: blackfam972
2 Replies

9. Programming

text boxes, radio buttons , check boxes in c++ on unix

Hi ! Please tell me how to get radio buttons, text boxes , check boxes , option buttons , pull down menus in C++ on Unix. I think it would be done using curses.h ..but that's all i know. TIA, Devyani. (3 Replies)
Discussion started by: devy8
3 Replies
Login or Register to Ask a Question