Your Ad Here

Kamis, 15 Oktober 2015

Unix Tip: MULTIPLE SYSTEM FILE UPDATES

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 3536 - October 15, 2015

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


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 james.a.dennis@ameritech.net



--------------------------------------------------------------------------
To Subscribe: http://www.ugu.com/sui/ugu/show?tip.subscribe
To Unsubscribe: http://www.ugu.com/sui/ugu/show?tip.unsubscribe
To Submit A Tip: http://www.ugu.com/sui/ugu/show?tip.today

==========================================================================
DISCLAIMER: All UNIX HOT TIPS ARE OWNED BY THE UNIX GURU UNIVERSE AND ARE
NOT TO BE SOLD, PRINTED OR USED WITHOUT THE WRITTEN CONSENT OF THE UNIX
GURU UNIVERSE. ALL TIPS ARE "USE AT YOUR OWN RISK". UGU ADVISES THAT
ALL TIPS BE TESTED IN A NON-PRODUCTION DEVELOPMENT ENVIRONMENT FIRST.

Unix Guru Universe - www.ugu.com - tips@ugu.com - Copyright 1994-2001
==========================================================================

Tidak ada komentar:

Posting Komentar

Your Ad Here
Free Automatic Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink