UGU Unix Guru Universe
For Unix Admins, By Unix Admins
Follow ugucom on Twitter      Search  in 
Home
BEGINNERS & USERS

Events

Internet
 
 Linux
BEGINNERS & USERS
Software
Linux Vendors
Usenet NewsGroups
Books & Publications
 
 Shop
Cool Admin Gifts!
Gadgets
T-Shirts
Books
 
 Unix Guru Universe
About
Add Link
Feedback
 
 
UGU: Unix Guru Universe - Unix Tip #4552- August 28, 2014 - Home : Help : Today's Tip
Unix Tip #4552- August 28, 2014

MULTIPLE SYSTEM FILE UPDATES


This Tip will show one of the ways to update
multiple systems with one script unattended:

There are a variety of ways to accomplish this,
but this one requires NO update to the remote
systems except for the files you wish to update
(i.e. - no update to .rhosts or hosts.equiv
type files). I use an ftp macro as follows:

------------------------------- CUT HERE ---------------------------

#!/bin/ksh
#
# program: update-all-workstations
# purpose: To ensure that all workstations have the same update of
# specific programs.
#
# notes: We run a ping command also to see if host is alive
# before we try to do the updates.
#
hosts=`ypcat hosts | grep col[d-f] | awk '{print $2}'`
for host in $hosts
do
alive=`ping -v $host 1 | awk '{print $3}'`
if [ $alive = "alive" ];
then
echo $host >> live-hosts
else
echo $host >> dead-hosts
fi
done

# This next sequence is totally unneeded if all workstations have a .rhosts
# file that allows the server (or system running this script) root access.
# If .rhosts is used, eliminate the prompting for the password and the
# building of the .netrc file.
#
# This next line assumes that ALL workstations have the same password
# If this is not the case, then administration becomes somewhat more
# cumbersome. Move the following 2 lines down to below the next do statement
# if the password differs from workstation to workstation.
echo "Please enter the root password for the workstations:\c"
read password
for host in `cat live-hosts`
do
echo "machine $host login root password $password" > $HOME/.netrc
chmod 600 $HOME/.netrc
echo "macdef init" >> $HOME/.netrc
echo "prompt" >> $HOME/.netrc
echo "binary" >> $HOME/.netrc
echo "put /tmp/myfiles.tar /tmp/myfiles.tar" >> $HOME/.netrc
echo "close" >> $HOME/.netrc
echo "quit" >> $HOME/.netrc
echo "\n\n" >> $HOME/.netrc

# these next few steps may seem redundant, but they are necessary.
# if you are using a .netrc file, it must be whacked after the ftp and
# before the rexec command

rm $HOME/.netrc
echo "machine $host login root password $password" > $HOME/.netrc
chmod 600 $HOME/.netrc
rexec $host "cd /usr/local; tar xvf /tmp/myfiles.tar"
done

# End of this script
#################################################################

Now, if you are using .rhosts files, the whole process becomes much
simpler.

Lets examine a script would look like if we are using .rhosts files on
each
workstation to allow the server or UNIX admin workstation to have root
access.


---------------------------- CUT HERE -----------------------------

#!/bin/ksh
#
# program: update-using-rhosts
# purpose: To ensure that all workstations have the same update of
# specific programs.
#
# notes: We run a ping command also to see if host is alive
# before we try to do the updates.
#
hosts=`ypcat hosts | grep col[d-f] | awk '{print $2}'`
for host in $hosts
do
alive=`ping -v $host 1 | awk '{print $3}'`
if [ $alive = "alive" ];
then
echo $host >> live-hosts
else
echo $host >> dead-hosts
fi
done

for host in `cat live-hosts`
do

# first we do a tar archive to standard out, then pipe to rsh to the
# host, make # sure we are in the root directory, then tar extract from
# standard in

tar c

 
Copyright 1994-2011 Unix Guru Universe