Date: Tue, 9 Jun 1998 15:02:16 -0600 (MDT) From: Atipa <freebsd@atipa.com> To: jktheowl@bga.com Cc: freebsd-stable@FreeBSD.ORG Subject: NIS client maintenance script Message-ID: <Pine.BSF.3.96.980609145526.5230B-100000@altrox.atipa.com>
next in thread | raw e-mail | index | archive | help
Everyone,
You may find this script to be of use for NIS clients. It can be run from
crontab every minute or so to make sure NIS connections are up and
running.
It disables NIS authentication during network failures, and
resets and enables NIS if the connection is restored.
Must be run as root. May work with /bin/sh, but I like bash better.
WARNING!!! This may modify your /etc/master.password file. If you can not
understand what it does, do not use it! :)
Kevin
-----
#!/usr/local/bin/bash
# This script maintains NIS client connections on simple networks
# Rev. 1.0, 05-09-98, Kevin McCarthy (kmcc@atipa.com)
# It disables NIS authentication during network failures, and resets
# and enables NIS if the connection is restored.
# User defined variables
nis_host="host.domain.tld" # required
nis_domainname="freakazoid" # required
ypbind_args="-s -ypsetme" # -s for security
ypset_args="$nis_host" # "" for no ypset
# Clearspace for readability
echo " "
# Find current state (bool) of NIS
nis_state=`grep + /etc/master.passwd && ps ax |grep yp`
if [ -n "$nis_state" ]; then
echo NIS authentication is ON
else
echo NIS authentication is OFF
fi
# Set up NIS conditional functions
function nis_down () {
echo "Error: $nis_problem"
if [ -n "$nis_state"]; then
echo "Disabling NIS authentication"
umask 077
grep -v + /etc/master.passwd > /root/mp.nonis
mv /etc/master.passwd /etc/master.passwd.nis
mv /root/mp.nonis /etc/master.passwd
pwd_mkdb -p /etc/master.passwd
else
echo "NIS remaining disabled"
fi
exit 1
}
function nis_reset () {
if [ -n "$nis_problem"]; then
echo "Error: $nis_problem"
fi
echo -n "Resetting NIS services... "
killall ypbind >> /dev/null
domainname $nis_domainname
ypbind $ypbind_args
if [ -n "$ypset_args"]; then
ypset $ypset_args
fi
echo "Done"
reset_done="true"
}
function nis_up () {
if [ -z "$nis_state" ]; then
echo "NIS services restored. Enabling NIS authentication"
umask 077
mv /etc/master.passwd.nis /etc/master.passwd
pwd_mkdb -p /etc/master.passwd
fi
nis_working="true"
}
echo -n "Network connecion to $nis_host is "
up=`ping -c1 $nis_host | grep transmitted | awk -F, '{print $2}' \
| awk '{print $1}'`
if [ "$up" = "1" ]; then
echo ON
else
echo OFF
nis_problem="host not reachable (ping failed)"
nis_down
fi
while [ -z "$nis_working" ]; do
# Check if NIS is bound
nis_bound=`ypwhich`
if [ "$nis_bound" = "$nis_host" ]; then
echo NIS binding to $nis_bound is ON
nis_up
else
if [ -z "$reset_done" ]; then
nis_problem="NIS binding to $nis_host is OFF"
nis_reset
else
echo "Reset Failed; disabling NIS services"
nis_down
fi
fi
done
echo "Exiting"
echo " "
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.96.980609145526.5230B-100000>
