今天晚上搞了个nis服务的脚本,哪位高手给指点一下。

nis-server.sh

#!/bin/bash
# create a nis server and nfs server. but you mast installed ypserv.
echo "Please enter NIS domainname!!"
read domain
echo "NISDOMAIN=$domain" >>/etc/sysconfig/network
nisdomainname=$domain
#/usr/lib/yp/ypinit -m   这里哪位高手给帮下忙如何在脚本里指定Ctrl+D
/var/yp/make
service ypserv restart
echo "/home/ 192.168.1.0/255.255.255.0(rw,sync)" >>/etc/exports
service nfs restart
chkconfig ypserv on
chkconfig nfs on
unset domain
service iptables stop
#由于对iptables不是很懂,现在只是做实验时把它关闭了。其实还可以再添加一些其它的功给。

nis-client.sh

#!/bin/bash
# This is nis client and autofs script.
# this script mast have dns server.
echo "Please enter NIS domain name!!"
read domain
echo "NISDOMAIN=$domain" >>/etc/sysconfig/network
nisdomainname=$domain
echo "If you not dns server. Then please ehter the domain's IP address. else enter no"
read ip
if [ $ip!=no ];
then echo "$ip $domain" >>/etc/hosts;
mv /etc/nsswitch.conf /etc/nsswitch.conf.back
cat /etc/nsswitch.conf.back | grep -v passwd | grep -v shadow |grep -v group >/etc/nsswitch.conf
echo "passwd: files nis" >>/etc/nsswitch.conf
echo "shadow: files nis" >>/etc/nsswitch.conf
echo "group: files nis" >>/etc/nsswitch.conf
service iptables stop
service portmap restart
service ypbind restart
echo "/home /etc/auto.home" >>/etc/auto.master
touch /etc/auto.home
echo "* -rw,soft,intr 192.168.1.11:/home/&" >>/etc/auto.home
service autofs restart
unset domain
unset ip
else
mv /etc/nsswitch.conf /etc/nsswitch.conf.back
cat /etc/nsswitch.conf.back | grep -v passwd | grep -v shadow |grep -v group >/etc/nsswitch.conf
echo "passwd: files nis" >>/etc/nsswitch.conf
echo "shadow: files nis" >>/etc/nsswitch.conf
echo "group: files nis" >>/etc/nsswitch.conf
service iptables stop
service portmap restart
service ypbind restart
echo "/home /etc/auto.home" >>/etc/auto.master
touch /etc/auto.home
echo "* -rw,soft,intr 192.168.1.11:/home/&" >>/etc/auto.home
service autofs restart
unset domain
unset ip
fi

#这个脚本有点惭愧,不知道if语句里怎么让else指定执行某一行,也望高手能够解决下。

谢谢!!