Unix Tip #4552- August 28, 2023


SEARCH : Home : Help : Today's Tip

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 cvf - ./usr/local/bin | rsh $host "cd /; tar xvf -"
done

# End of this script


Obviously the second method is easier, but obviously it depends on your
site characteristics on which you would use.

If you need assistance with these types of scripts, I will assist you,
but keep in mind, I accept no responsibility for anything that
happens to you or your site due to the use of these scripts.
Only an experienced admin should attempt to use these scripts, and
you should always have the appropriate safety precautions in
place.

James A. (Jamie) Dennis jdennis@netset.com


NOTE: All tips provided are USE AT YOUR OWN RISK. Tips are submitted by various unix admins around the globe. UGU suggest you read and test each tip in a non-volitile environment before placing into production.


LAST 5 TIPS
4551 - REWIND A TAPE FAST
4550 - CRYPT AN ASCII FILE
4549 - MORE AND VI OR MORE VI
4548 - EXTRACT CORRUPTED TAR FILE
4547 - EDIT A LOST FILE


I want to SUBSCRIBE and get a UGU Tip everyday.
I want to UNSUBSCRIBE and NOT get a UGU Tip everyday.

If you have a UNIX TIP let us know, we just may use it:
(All tips become the property of the Unix Guru Universe)
Email Address:

Yes, email me a Hot Unix Tip everday.

Enter Hot Unix Tip (optional):

Yes, I will support this tip

Captcha (not case sensitive):


Please enter the above letters:


HOME | Flavors | Admin | Network | Security | S/W | Help | Events | Vendors | Careers | Internet
About | Add Link | Feedback | Search

Copyright © 1994-2005 Unix Guru Universe