Dynamic IP address-Based WWW server in Linux

Source: Internet
Author: User
Tags perl script
Article Title: implement a dynamic IP address-Based WWW server in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
The Dynamic IP-based server can also open the www Service to accept client access, which can be achieved through the following script. Please first establish a PPP connection, configure Httpd, and test whether it can work.
Create the following script program:
* Web_up: the script used to upload a webpage.
* Web_down: indicates the script for disconnecting.
* Update_uppage: the Perl script creates an HTML page containing the updated IP address.
* Up. HTML_source; Fixed page.
* Down. HTML: Page used for disconnection.
*/Etc/add,/etc/last_add: The file that stores the IP address.
* Ip-down and ip-up: files uploaded when the PPP connection is disconnected and the connection is rejected.
  
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
  
Run the following script:
  
#! /Bin/sh
If web_down
Then
Shutdown-h now
Else
Echo "can not web_down"
Exit 1
Fi
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.