1828170 Members
2665 Online
109975 Solutions
New Discussion

Script Help.

 
joe_91
Super Advisor

Script Help.

Hi All:

We have a script to push the homedir's for nis and runs on the master server. There is this portion of the code i am having problem with. It reads a hosfile and pushes the dir's to them. This is the hostfile

MASTER=tx274
SLAVE1=tx275
SLAVE2=tx276
SLAVE3=tx277
I have attached the portion of the script which does the pushing of the dir's which doesn't function. I think this was written with one SLAVE entry in the above hostfile.now we have 3 entries. Can someone help please?

Thanks
Joe.
8 REPLIES 8
Justo Exposito
Esteemed Contributor

Re: Script Help.

Hi Joe,

Try this changes:

for cur_line in hostfile |
do
if `echo ${cur_line} | grep "^SLAVE" > /dev/null`
then
SLAVE=`echo ${cur_line}| cut -d"=" -f2`
remsh ${SLAVE} hostname > /dev/null
if test $? -eq 0
then
echo "Copying password file to the Slave - $SLAVE."
rcp ${PASSWD} ${SLAVE}:${PASSWD}
else
echo "\n\n\t\tUnable to reach the Slave - ${SLAVE}.\n\n"
fi
fi
done

Regards,

Justo.
Help is a Beatiful word
Justo Exposito
Esteemed Contributor

Re: Script Help.

Hi Again,

Sorry a mistake:
for cur_line in hostfile |
do

This is the good lines:
for cur_line in hostfile
do

Regards,

Justo.
Help is a Beatiful word
Tim D Fulford
Honored Contributor

Re: Script Help.

Unless I'm much mistaken you are trying to copy the /etc/passwd file to all the slaves... You do not need to do this if you have nis yp_xfr (I think) can do it or just re-make the NIS DB & the passwd file will be exported to all the slaves (ypmake)

tim
-
Tim D Fulford
Honored Contributor

Re: Script Help.

Here's my version

#!/usr/bin/ksh
PASWD=/etc/passwd

for line in $(cat hostfile)
do
slaveyn=$(echo $line | awk -F"=" 'BEGIN{f=0}; $1=/SLAVE/{f=1}; END{print
f}')
host=$(echo $line | cut -d"=" -f2)
if [ $slaveyn -eq 1 ]
then
remsh $host /usr/bin/hostname >/dev/null 2>&1
if [ $? -eq 0 ]
then
echo "Copying password file to slave - $host"
rcp ${PASWD} $host:${PASWD}
else
echo "unable to reach slave $host"
fi
fi
done

Tim
-
Tim D Fulford
Honored Contributor

Re: Script Help.

I too made a mistake (I wasn't going to test it copying 'round passwd files!!!)

in awk statement I mean ... $1~/SLAVE/{.... not =

Tim
-
joe_91
Super Advisor

Re: Script Help.

Hi:

I am still getting only tx277 as $SLAVE. Will that help. I think it should capture all the 3 slaves and that was the problem.

Thanks
Joe.
Jordan Bean
Honored Contributor

Re: Script Help.


Try this.


#!/usr/bin/sh
grep ^SLAVE hostfile | while IFS='=' read junk slave comment
do
if remsh $slave hostname 0<&- 1>&2
then
echo "Copying password file to slave $slave."
else
echo "Unable to reach slave $slave."
fi
done 2> /dev/null


Notice that we are closing stdin to remsh; Otherwise it will slurp up the rest of the grep stream.

Jordan Bean
Honored Contributor

Re: Script Help.


Oh, I forgot the `rcp /etc/passwd ${slave}:/etc/passwd` part... Sorry.