scripts web_up: #!/bin/sh #check new ip new_ip() { if [ -f /etc/add ] ; then if [ -f /etc/last-add ] ; then if /usr/bin/diff /etc/add /etc/last_add >/dev/null ; then exit 1 else return 0 fi else return 0 fi else exit 1 fi } #check whether maroon is connected try_connect() { if ping -c4 -13 128.101.118.21 2>& | grep "0 packets" > /dev/null then return 1 else return 0 fi fi } if try_connect then touch /var/run/maroon_connected else rm -f /var/run/maroon_connected fi # FTP to update page if [ -f /var/run/maroon_connected ] && new_ip then # update_uppage is perl scripts, exit status is opposite of shell if ( ! /home/honglu/public_HTML/update_uppage ) then cd /home/honglu/public_HTML if echo "put up.HTML /nlhome/m508/luxxx012/dynamic.HTML" | /usr/bin/FTP maroon then rm -f /etc/last_add cp /etc/add /etc/last_add exit 0 else exit 1 fi fi else exit 1 fi
scripts web_down # FTP to send down.HTML page if [ -f /var/run/maroon_connected ] then cd /home/honglu/public_HTML if echo "put down.HTML /nlhome/m508/luxxx012/dynamic.HTML" | /usr/bin/FTP maroon then rm -f /etc/last_add else exit 1 fi else exit 1 fi
执行如下脚本:
#!/bin/sh if web_down then shutdown -h now else echo "can not web_down" exit 1 fi