sync_scs.sh

2
#!/bin/ksh # Test if this is an HACMP cluster. If not, just exit. if [ ! -x /usr/es/sbin/cluster/clstrmgr ] ; then exit fi # what is the service address? SERVICEADDR=`/usr/es/s bin/cluster/utilities/cl lsif -c | grep service | grep ethe r | sort -dfu | cut -f1 -d: | sort -dfu` if [ -z "$SERVICEADDR" ] ; then # No service address found exit fi # is this service address configured on this host? SERVICEIP=`/usr/bin/ne tstat -i | grep ${SERVICEADDR} | wc -l | awk '{print $1}'` # what is the current host? CURRENTHOST=`/usr/es/s bin/cluster/utilities/ge t_local_nodename` # what is the other node? OTHERSERVER=`/usr/es/s bin/cluster/utilities/cl lsnode -c | grep -v "^#node" | gre p -v "${CURRENTHOST}:" | cut -f1 -d:` # is there a service address configured on this server? if [ ${SERVICEIP} -eq 0 ] ; then # Service IP is not configured on this server. No need to sync. exit fi echo "Copying from ${CURRENTHOST} to ${OTHERSERVER}" scp -p /etc/passwd ${OTHERSERVER}:/etc/passwd scp -p /etc/security/passwd ${OTHERSERVER}:/etc/securi ty/passwd scp -p /etc/security/user ${OTHERSERVER}:/etc/secu rity/user scp -p /etc/security/group ${OTHERSERVER}:/etc/sec urity/group scp -p /etc/security/limits ${OTHERSERVER}:/etc/securi ty/limits scp -p /etc/security/lastlog ${OTHERSERVER}:/etc/secur ity/lastlog scp -p /etc/group ${OTHERSERVER}:/etc/group scp -p /etc/sudoers ${OTHERSERVER}:/etc/sudoer s echo "Correct root GECOS field in /etc/passwd on ${OTHERSERVER}" chuser gecos="${CURRENTHOST} root user" root ssh ${OTHERSERVER} "chuser gecos='${OTHERSERVER} root user' root" # copy the crontabs and make sure they get activated on the standby node # make a temporary directory for storing the crontab files echo "Synchronizing crontabs" ssh ${OTHERSERVER} mkdir -p /tmp/cron.$$ # copy over the crontab files to the temporary directory cd /var/spool/cron/crontab s tar -cvf - . | ssh ${OTHERSERVER} "cd /tmp/cron.$$; umask 000 ; cat | tar -xvpf -" # make sure every user can access this temporary crontab directory ssh ${OTHERSERVER} chmod -R 777 /tmp/cron.$$/ # enable the crontab for every user on the ${OTHERSERVER} for file in `ls /var/spool/cron/crontabs/*` ; do # only update the file if there's a difference found tab=`basename $file`

Upload: chandrasro

Post on 14-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

7/29/2019 sync_scs.sh

http://slidepdf.com/reader/full/syncscssh 1/2

#!/bin/ksh

# Test if this is an HACMP cluster. If not, just exit.if [ ! -x /usr/es/sbin/cluster/clstrmgr ] ; then

exitfi

# what is the service address?SERVICEADDR=`/usr/es/sbin/cluster/utilities/cllsif -c | grep service | grep ether | sort -dfu | cut -f1 -d: | sort -dfu`

if [ -z "$SERVICEADDR" ] ; then# No service address foundexit

fi

# is this service address configured on this host?SERVICEIP=`/usr/bin/netstat -i | grep ${SERVICEADDR} | wc -l | awk '{print $1}'`

# what is the current host?CURRENTHOST=`/usr/es/sbin/cluster/utilities/get_local_nodename`

# what is the other node?OTHERSERVER=`/usr/es/sbin/cluster/utilities/cllsnode -c | grep -v "^#node" | gre

p -v "${CURRENTHOST}:" | cut -f1 -d:`

# is there a service address configured on this server?if [ ${SERVICEIP} -eq 0 ] ; then

# Service IP is not configured on this server. No need to sync.exit

fi

echo "Copying from ${CURRENTHOST} to ${OTHERSERVER}"scp -p /etc/passwd ${OTHERSERVER}:/etc/passwdscp -p /etc/security/passwd ${OTHERSERVER}:/etc/security/passwdscp -p /etc/security/user ${OTHERSERVER}:/etc/security/userscp -p /etc/security/group ${OTHERSERVER}:/etc/security/group

scp -p /etc/security/limits ${OTHERSERVER}:/etc/security/limitsscp -p /etc/security/lastlog ${OTHERSERVER}:/etc/security/lastlogscp -p /etc/group ${OTHERSERVER}:/etc/groupscp -p /etc/sudoers ${OTHERSERVER}:/etc/sudoers

echo "Correct root GECOS field in /etc/passwd on ${OTHERSERVER}"chuser gecos="${CURRENTHOST} root user" rootssh ${OTHERSERVER} "chuser gecos='${OTHERSERVER} root user' root"

# copy the crontabs and make sure they get activated on the standby node# make a temporary directory for storing the crontab filesecho "Synchronizing crontabs"ssh ${OTHERSERVER} mkdir -p /tmp/cron.$$

# copy over the crontab files to the temporary directorycd /var/spool/cron/crontabstar -cvf - . | ssh ${OTHERSERVER} "cd /tmp/cron.$$; umask 000 ; cat | tar -xvpf-"# make sure every user can access this temporary crontab directoryssh ${OTHERSERVER} chmod -R 777 /tmp/cron.$$/# enable the crontab for every user on the ${OTHERSERVER}for file in `ls /var/spool/cron/crontabs/*` ; do

# only update the file if there's a difference foundtab=`basename $file`

7/29/2019 sync_scs.sh

http://slidepdf.com/reader/full/syncscssh 2/2

myfile=`/usr/bin/cksum /var/spool/cron/crontabs/${tab}`yourfile=`ssh ${OTHERSERVER} /usr/bin/cksum /var/spool/cron/crontabs/${t

ab}`if [ "${myfile}" != "${yourfile}" ] ; then

ssh ${OTHERSERVER} su - $tab -c crontab /tmp/cron.$$/$tab > /dev/null 2>/dev/null

echo "Enabled crontab for user ${tab}."else

echo "No changes for the crontab of user $tab found. Skipping."fi

done# delete our temporary directoryssh ${OTHERSERVER} rm -rf /tmp/cron.$$# now make sure the standby node doesn't have any crontabs that the active nodedoesn't havessh ${OTHERSERVER} ls /var/spool/cron/crontabs | sed "s/ //g" | while readfile ; do

unset resultresult=`ls -als /var/spool/cron/crontabs/${file} 2>/dev/null`if [ -z "${result}" ] ; then

# found a file on the standby that doesn't exist on the primary.delete this file

# run crontab -r. this will only work on crontab files of actualusers.

# remove the file afterwards, just in case the user didn't existanymore.ssh ${OTHERSERVER} "crontab -r ${file} 2>/dev/null;rm -f /var/sp

ool/cron/crontabs/${file}"echo "Crontab of user $file on ${OTHERSERVER} deleted."

fidone