基於動態ip的服務器同樣可以開設www服務接受客戶端的訪問,這可以通過以下的腳本來實現.請先建立PPP連接,配置好Httpd,測試它可以工作. 建立如下的腳本程序: * web_up: 上載網頁的腳本. * web_down: 斷開連接的腳本. * update_uppage: Perl 腳本創建包含更新IP地址的Html頁面. * up.HTML_source; 固定部分的頁面. * down.HTML: 連接斷開時使用的頁面. * /etc/add, /etc/last_add: 存放IP地址的文件. * ip-down, ip-up: PPP連接斷開和連接時拒絕上載的文件. 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