基于动态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
(出处:http://www.sheup.com)