gjhicks
Group: Members
Posts: 108
Joined: April 2004 |
|
Posted: Mar. 03 2006,12:42 |
|
Hi,
Like many other ADSL users, I do not have a static IP, with my ISP changing my IP address at a irregular intervals.
Using 'ssh' with a redirected port and WinSCP, I can access my DSL server remotely. One problem - how to know the current IP address of the DSL server?
Below is my solution:
1) Install 'cron' (use apt-get)
2) Use cron to call the following script (I am sure the script could be more elegant but I am just a beginner):
#!/bin/bash # # Get the current external IP address of the DSL server, # via the 'whatismyip' webpage
wget -q http://www.whatismyip.com/
# Get just the first line, that is the string containing the IP address, # then trim from the left to remove the html formatting
grep '<title>WhatIsMyIP' index.html | \ awk '{ d = length($3); print substr($3, 1, d-8) }' > tmp1
# Get the current DSL server time and construct the output string
STR1=$(date)" - DSL Server: Current IP Address = "$(cat tmp1)
# Write the string to a file
echo $STR1 >myip.txt
# Use the command line ftp to send the file to a server, # using .netrc to automate the process
ftp ftp.servername.com
# clean up rm index.html rm tmp1
3) Contents of /home/dsl/.netrc
machine ftp.servername.com login ftp-username password mypassword macdef init prompt hash lcd /home/dsl cd public_html mdelete myip.txt put myip.txt quit # newline terminates macro
4) Crontab contents
0 2,6,10,14,18,22 * * * /home/dsl/myip.sh
The above instruction runs the myip.sh script every 4 hours from 2am.
By the way, to create or edit the crontab instruction file, you need to set up the editor used by crontab, which defaults to /usr/bin/editor. I made a symbolic link to /bin/nano.
The end result is that, entering the URL to the text file in a browser, I get the current IP address for the DSL server.
------------------------------------------------------------------------------------------
BUT, I would much rather email the text file but I can not get a command line email agent to work in DSL.
Can anyone help me figure out how to get a command line email agent working in DSL?
Thanks
Geoff.
|