1834207 Members
2792 Online
110066 Solutions
New Discussion

Re: simple script

 
SOLVED
Go to solution
Craig Basham
Occasional Contributor

simple script

i need to write a script which will perform an 'rm' on a certain file on about 50 machines. I have a list of the machines hostnames in a file. As easy as this is for some reason my script will not work. Script as follows:

#!/bin/sh
HOSTLIST=/usr/local/hostlist
for HOST in $HOSTLIST
do
rsh $HOST rm /etc/file
done


Why oh why does it not work. I have tried many variants on this including the "while read .......done < /usr/local/hostlist" version.

Any ideas guys/gals?
8 REPLIES 8
Vincenzo Restuccia
Honored Contributor

Re: simple script

Try remsh $HOST -n "rm /etc/file"
boley janowski
Trusted Contributor

Re: simple script

vincenzo's comment will work, if it doesn't check the .rhost file and make sure your setup right in there.
Bill McNAMARA_1
Honored Contributor
Solution

Re: simple script

please test first!!!
Bill

usage filerm filename

#!/sbin/sh
export HOSTLIST=/root/list

for i in `cat $HOSTLIST`
do echo "===================================" echo "Doing $i"
remsh $i 'rm $1'
done
It works for me (tm)
Craig Basham
Occasional Contributor

Re: simple script

the "rsh" bit is not the problem. The script interprets /usr/local/hostlist as a machine hostname. i want it to read each entry in the file and perform an actiuon on it.
Bill McNAMARA_1
Honored Contributor

Re: simple script

Try the script!

for i in `cat $HOSTLIST`

Later,
Bill
It works for me (tm)
John Palmer
Honored Contributor

Re: simple script

Change your script to:-

#!/usr/bin/sh
HOSTLIST=/usr/local/hostlist
for HOST in $(< ${HOSTLIST})
do
remsh $HOST rm /etc/file
done

I'd test it first by changing the 'rm' to 'll'.

Regards,
John
Andreas Voss
Honored Contributor

Re: simple script

Hi,

here just another solution:

#!/bin/sh

cat /usr/local/hostlist | while read HOST
do
remsh $HOST rm /etc/file
done

Regards

Vincenzo Restuccia
Honored Contributor

Re: simple script

Or :

#!/bin/sh

while read HOST
do
remsh $HOST rm /etc/file
done < /usr/local/hostlist