程序错在哪了?
coolboycool
|
1#
coolboycool 发表于 2006-06-10 10:59
程序错在哪了?
复制内容到剪贴板
代码:#!/bin/bash#this function show mainmenu showmainmenu() { echo '> Main Menu*****************' echo ' 1.Dynamic Net Option' echo ' 2.Service Option' echo ' 3.NFS Option' echo ' 4.DHCP Option' echo ' 5.DNS configure' echo ' 6.Agent Option' echo ' 7.Samba Option' echo ' 8.Exit' echo '> ***************************' echo -n ' Please Select Function ID:' } #this function will config dynamic net option mynetconfig() { echo -n 'Input Device Name:' read device echo -n 'Input IP Address:' read ip echo -n 'Input gateway Ip:' read gw echo -n 'Input DNS IP:' read dns /sbin/ifconfig $device $ip flag=$? if ( test $flag -eq 0) then /sbin/route add default gw $gw flag=$? if ( test $flag -eq 0) then echo "nameserver $dns">>/etc/resolv.conf flag=$? fi fi if ( test $flag -eq 0) then echo "OK,Successfully!" else echo "Sorry,Failed!" fi showmainmenu } #this function do service myservice() { canexit=0 while ( test $canexit !=1) do echo'>>Service Sub Menu ************' echo' 1.Show All Services Status' echo' 2.[start/stop/restart] Service' echo' 3.Run Level Starting of Service' echo' 4.Back to Main Menu' echo'>>******************************' echo -n'Please Select function ID about Service:' read funid case $funid in 1) /sbin/service --status-all;; 2) echo -n 'Input Service Name:' read servicename echo -n 'Input [start/stop/restart]:' read operation /sbin/service $servicename $operation ;; 3)echo -n 'Input Service Name:' read servicename echo -n 'Input Run Level:' read runlevel /sbin/chkconfig $servicename --level 0123456 off /sbin/chkconfig $servicename --level $runlevel on ;; 4)canexit=1;; esac done showmainmenu } #this function do nfs option mynfs() { echo "portmap:ALL">>/etc/hosts.allow echo -n 'Input you driect:' read driect echo -n 'Input read allow:' read rallow echo -n 'Input read and write allow:' read rwallow if [ "$rwallow" != " " ] then if [ "$rwallow" != " " ] then echo "$driect $rallow*(ro) $rwallow(rw,sync)" > /etc/exports else echo "$driect $rallow*(ro,sync)" > /etc/exports fi else if [ "$rwallow" != " " ] then echo "$driect $rwallow*(rw,sync)" fi fi /sbin/service portmap start /sbin/service nfs start showmainmenu } #this function do DHCP Option mydhcp() { echo -n 'Input lease time:' read time echo -n 'Input Subnet Mask:' read mask echo -n 'Input Gateway:' read gw echo -n 'Input DNS IP:' read dns echo -n 'Input IP Range:' read IP flag=$? if [ $flag -eq 0 ] then /sbin/touch /var/dhcp/dhcp.lease flag=$? fi if ( test $flag -eq 0) then echo"OK,Successfully!" else echo"Sorry,Failed!" fi showmainmenu } #this function do dns Option mydns() { echo -n 'selcet you want to do====' echo -n ' 1.Add Zone' echo -n ' 2.Add Arpa Zone' echo -n '=========================' echo -n ' Please Select function ID:' read ID case $ID in 1) echo -n 'Input Zone Name:' read zname echo -n 'Input Zone database:' read db echo -n 'zone "$zname" { type master file "$db" }' >> /etc/namd.conf /sbin/touch /var/named/db.$db echo "\$TTL 86400" > /var/named/$db1 echo "@ IN SOA $zone1. master.$zone1 (" >>/var/named/$db1 echo " 2005122215 ; Serial" >>/var/named/$db1 echo " 28800 ; Refresh" >>/var/named/$db1 echo " 14400 ; Retry" >>/var/named/$db1 echo " 3600000 ; Expire" >> /var/named/$db1 echo " 86400) ; Minimum" >>/var/named/$db1 echo " IN NS $zone1" >> /var/named/$db1 echo "localhost. IN A 127.0.0.1" >> /var/named/$db1 flag=$? while ( test $flag -eq 0 ) do echo -n "Input the DNS name[ep:www2] in $zname :" read one echo -n "Input $one IP address [ep:10.0.0.2]:" read ip echo "$one. IN A $ip">>/var/named/$db1 echo -n 'do you want to configure the other one?[yes/no]:' read option if (test $option) then if ( test $option == yes || test $option == y) then flag=0 else flag=1 fi else flag=1 fi done 2) echo -n 'Input IP-Name:' read ipname echo -n 'Input Arpa IP Name:' read arpaname echo -n 'zone "$ipnamein-addr.arpa" { type master file "$arpaname" }' >> /etc/namd.conf /sbin/touch /var/named/db.$arpaname echo "\$TTL 86400" > /var/named/$db2 echo "@ IN SOA $zone1. master.$zone1 (" >>/var/named/$db2 echo " 2005122215 ; Serial" >>/var/named/$db2 echo " 28800 ; Refresh" >>/var/named/$db2 echo " 14400 ; Retry" >>/var/named/$db2 echo " 3600000 ; Expire" >> /var/named/$db2 echo " 86400) ; Minimum" >>/var/named/$db2 echo " IN NS $zone1" >> /var/named/$db2 echo "1 IN PTR localhost.$zone1" >> /var/named/$db2 flag2=$? while ( test $flag2 -eq 0 ) do echo -n "Input the IP address[ep:10.0.0.1]:" read ip2 echo -n 'Input the DNS name[ep:www2]:' read one echo "$ip2 IN PTR $one.$zone1">>/var/named/$db2 echo -n 'you want allocate another people ip[yes/no]:' read option if (test $option) then if ( test $option == yes || test $option == y) then flag2=0 else flag2=1 fi else flag2=1 fi done fi else funid=0 fi showmainmenu } #this function do Agent Option myagent() { echo -n 'config eth0:' read IP /sbin/ifconfig eth0 $IP echo -n 'config gw:' read GW echo "nameserver $GW" > /etc/resolv.conf echo -n 'net' read NET echo -n 'config ip_forward:' read NUM echo $NUM > /proc/sys/net/ipv4/ip_forward echo -n 'config eth0:0' read IP1 /sbin/ifconfig eth0:0 $IP1 /sbin/iptables -t nat -A PREROUTING -i eth0 -d $IP -j DNAT --to $IP1 /sbin/iptables -t nat -A POSTROUTING -o eth0 -s $NET/24 -j SNAT --to $IP showmainmenu } simplesambaconfig() { echo 'welcome to configure the simple samba' echo -n 'please input the workgroup:' read workgroup echo -n 'please input your sambaname:' read serverstring echo -n 'please input you netbios name:' read netbiosname echo -n 'please input what IP you permit visit,eg(192.168.0.):' read hostallow echo -n 'please input the security you want(share or user);' read security /sbin/ifconfig eth0 | grep inet echo -n 'please input the IP of your:' read interface echo "[global] workgroup = $workgroup server string = $serverstring netbios name = $netbiosname hosts allow = $hostallow interfaces = $interface security = $security client code page = 936 log file = /var/log/samba/log.%m max log size = 0 socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192 dns proxy = no" > $sambapath/smb.conf if ( test $security == user ) then echo " encrypt passwords = yes smb passwd file = $sambapath/smbpasswd" >> $sambapath/smb.conf echo "[homes] comment = Home Directories browseable = no writable = yes valid users = %S create mode = 0664 directory mode = 0775" >> $sambapath/smb.conf echo "[myshare] comment = myown samba share path = /home/share read only = no guest ok = no create mode = 0664 directory mode = 0775" >> $sambapath/smb.conf /bin/mkdir /home/share /bin/chmod 777 /home/share echo "the /home/share is the security directory need passwd" echo 'please press Enter to continue' read passwdhhh /bin/touch $sambapath/smbpasswd # /bin/chown root:root smbpasswd; chmod 600 smbpasswd echo -n 'please input the new user name: ' read username /usr/sbin/useradd $username /usr/bin/passwd $username echo 'please input the smbpasswd should the same as the passwd:' /usr/bin/smbpasswd -a $username fi echo "[share] comment = my samba share path = /var/samba read only = no guest ok = yes writable = yes create mode = 0664 directory mode = 0775" >> $sambapath/smb.conf /bin/mkdir /var/samba /bin/chmod 777 /var/samba touch $sambapath/codepages echo "client code page = 936 character set = gb2312" >> $sambapath/codepages echo 'please input the ip you want permit' echo -n 'eg:192.168.0.1 zhangshan:' read lmhostspermit echo $lmhostspermet >> $sambapath/lmhosts } #samba配置主程序 rght=boy sambaconfig() { sambaexitflag=1 echo "[email="$coy$riht@$cpy$riht"]$coy$riht@$cpy$riht[/email]" echo 'stop the samba server:' /sbin/service smb stop echo 'welcome to configure your own samba:' echo -n 'please input which system being using:' read system if ( test $system == "turbolinux" ) then sambapath=/etc else sambapath=/etc/samba fi cp $sambapath/smb.conf $sambapath/smbold.conf echo "I have copy the smb.conf to $sambapath/smbold.conf.If you make mistake,you can cp $sambapath/smbold.conf $sambapath/smb.conf to revert!" echo -n 'please press the enter:' read startflag while ( test $sambaexitflag != 0 ) do echo 'samba configure menu:' echo '1: configure a new samba simple' echo '2: manage samba ' echo '3: add new configure' echo '4: change configure' echo '5: Show Samba configure' echo '6: Exit to mainmenu' echo -n 'please input the ID;' read sambaid case $sambaid in 1) simplesambaconfig ;; 2) sambamanageexitflag=1 while ( test $sambamanageexitflag != 0 ) do echo 'welcome to manage your samba' echo '1:manamge samba users' echo '2:add or del a share segment' echo '3:Exit to the sambamainmenu' echo -n 'please input the ID:' read sambamanageid case $sambamanageid in 1) echo -n 'please input "add" "recover" or "pause" to manage samba users:' read managesignal echo -n 'please input the user name: ' read username if ( test $managesignal == add ) then /usr/sbin/useradd $username /usr/bin/passwd $username /usr/bin/smbpasswd -a $username elif ( test $managesignal == pause ) then /usr/bin/smbpasswd -d $username elif ( test $managesignal == recover ) then /usr/bin/smbpasswd -e $username fi echo "$username had been $managesignal ed" echo -n "please press the Enter to continue:" read enter ;; 2) echo 'input the configure under global or del it:' vi $sambapath/smb.conf ;; 3) echo 'Turn to the sambamainmenu' sambamanageexitflag=0 ;; esac done ;; 3) sambainsertflag=1 while ( test $sambainsertflag != 0 ) do echo '1:insert command into segment' echo '2:Exit to samba menu' echo -n 'please input the ID:' read sambainsertid case $sambainsertid in 1) echo -n 'please input want to insert into what segment:' read segment echo 'please input the insert command' echo -n 'the command should be:WORKGROUP = MYGROUP:' read command cat $sambapath/smb.conf | sed "/\[$segment]/a\ $command" > $sambapath/smb.conf ;; 2) sambainsertflag=0 ;; esac done ;; 4) sambachangeflag=1 while ( test $sambachangeflag != 0 ) do echo 'welcome to change configure' echo '1:change configure' echo '2:Exit to samba mainmane' echo -n 'please input the ID:' read sambachangeid case $sambachangeid in 1) echo -n 'please input insert into what segment:' read segment echo 'please input the change command' echo -n 'the command(workgroup):' read command echo -n 'please input the commandoption:' read commandoption cat $sambapath/smb.conf | sed "/\[$segment]/,/\[/ s/$command.*/$command = $commandoption/" > $sambapath/smb.conf ;; 2) sambachangeexitflag=0 echo 'come back to the samba menu!' ;; esac done ;; 5) echo 'Following is sambaconfigure option:' /usr/bin/testparm ;; 6) echo 'Finish the samba configure and return to the manimenu' sambaexitflag=0 ;; esac done echo 'now restart the samba server :' cat /etc/hosts.deny | sed '/ALL:ALL/d' > /etc/hosts.deny /sbin/service smb start # echo 'please input the ip you want permit' # echo -n 'eg:192.168.0.1 zhangshan:' # read lmhostspermit # echo $lmhostspermet >> $sambapath/lmhosts echo -n 'Input "yes" to read or "no" to exit to the mainmenu:' read readflag if ( test $readflag == yes ) then echo 'Following is your now sambaconfigure;' /usr/bin/testparm echo "[email="$coy$riht@$cpy$rght"]$coy$riht@$cpy$rght[/email]" echo 'Goodbye!Thank you for your samba configure!' else echo "[email="$coy$riht@$cpy$rght"]$coy$riht@$cpy$rght[/email]" echo 'Goodbye!Thank you for your samba configure!' fi } coy=copy #here do mainmenu and selection funid=0 while( test $funid != 8 ) do showmainmenu read funid msg="you select function" case $funid in 1) mynetconfig() ;; 2) myservice() ;; 3) mynfs ;; 4) mydhcp() ;; 5) mydns() ;; 6) myagent() ;; 7) echo "Thank you !" ;; esac done |