I just finished a very simple script that reads out my IP-address from the ppp0 device, creates a small HTML file and uploads it to my webhoster so i can access my g4 from anywhere in the world. The script is the patchwork of a beginner, so any advice on making it nicer is greatly appreciated. It is run as a cronjob to assure the up-to-dateness of the IP.
Anyway, here's the script:
#!/usr/bin/perl use Net::FTP;
#all the neccessary info for loggin into the ftp server my $hostname = 'myftpserver.com'; my $user ='username'; my $pass = 'password';
#where on the server should which file go? my $dir = '/public_html'; my $file = '/Users/Shared/g4server.html';
#read out my ip address
my $ifconfig = `ifconfig ppp0`; # the ifconfig command gives the current network information
$ifconfig =~ /inet (\d+\.\d+\.\d+\.\d+)/; # extract the ip address with a regular expression
my $ip = $1;
# write it to a html file open (OUTPUT,">/Users/Shared/g4server.html"); print OUTPUT "<HTML><HEAD><TITLE>g4server address</TITLE></HEAD><BODY>"; print OUTPUT "<H1>Access g4server.local</H1>\n"; print OUTPUT '<a href=http://'; print OUTPUT $ip; print OUTPUT ">Apache</a><br />\n";
print OUTPUT '<a href=https://'; print OUTPUT $ip; print OUTPUT ":10000>Webmin</a><br />\n";
print OUTPUT "</BODY></HTML>"; close (OUTPUT);
#upload the html file
$ftp = Net::FTP->new($hostname); $ftp->login($user, $pass); $ftp->cwd($dir); $ftp->put($file); $ftp->quit;
Maybe it will brighten up some other beginners day :-)
Stephan