Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 04-27-2007, 11:12 AM   #1
Registered: Sep 2004
Distribution: Debian Etch
Posts: 45

Rep: Reputation: 15
Script problem: retrieving IP address via mail

Hi all! I have a problem with a script, that should send via email my IP address each time the system starts. The problem is that the script works nicely when I start it on a terminal, but it fails to get the IP address when it's started at boot time. Here it is:

uruclef@hexcellion:~$ cat /usr/local/bin/ipsend 

cd /tmp/
rm -f index.html*
rm -f tmpfile
wget #I get the mainpage of this site, with my IP dinamically written on it
cat index.html | grep 33AA33 | striphtml > tmpfile #I get the simple IP from the html file- striphtml is a sed script that.. well, strips html tags from lines
export TMP=$(cat /tmp/tmpfile)
echo $TMP | sendEmail -f -t -u "IP Address: $(date)" -s
The script is automatically started at boot only in init 2:

uruclef@hexcellion:/etc/rc2.d$ ls
K20tor           S20cupsys        S20nvidia-kernel  S50proftpd
K21gdm           S20dbus          S20openbsd-inetd  S89atd
README           S20dirmngr       S20privoxy        S89cron
S00bootsplash    S20exim4         S20pure-ftpd      S98usplash
S10sysklogd      S20firestarter   S20rsync          S99ipsend
S11klogd         S20kde-guidance  S20samba          S99kdm
S18portmap       S20lpd           S20ssh            S99rc.local
S20acpid         S20makedev       S21nfs-common     S99rmnologin
S20amule-daemon  S20nvidia-glx    S23ntp            S99stop-bootlogd
uruclef@hexcellion:/etc/rc2.d$ ls -l S99ipsend 
lrwxrwxrwx 1 root root 21 2007-04-27 17:48 S99ipsend -> /usr/local/bin/ipsend
When system boots, the output (stdout) of the script is successfull, and I receive the mail. But the mail is empty instead of containing the IP.

Any idea? I'm also open to other (and smarter! ) solutions

Last edited by Uruclef; 04-27-2007 at 11:14 AM.
Old 04-27-2007, 12:10 PM   #2
LQ Guru
Registered: Jan 2003
Location: Seymour, Indiana
Distribution: Distribution: RHEL 5 with Pieces of this and that. Kernel, KDE 3.5.8 and KDE 4.0 beta, Plu
Posts: 5,700

Rep: Reputation: 65
Not a debian user but is networking active in runlevel 2 on that distro?
Most use runlevel 3. And then most use runlevel 5 for gui but some use runlevel 4 for thier gui.
Maybe able to get that info from the /etc/inittab file.

Old 04-27-2007, 12:20 PM   #3
Registered: Mar 2007
Distribution: Debian
Posts: 547

Rep: Reputation: 67

just a guess, but could it be that the last line of your script is executed before wget has finished downloading the site ? It maybe worked in the konsole because the variable was already set with the right input. Try setting a 'sleep 2' or so between the last 2 commands or use a faster method to retrieve the ip.
If you are directly connected to the internet, simply use the ifconfig output. If you use a router, you could configure it to send syslog info to your box and retrieve the ip from there.
Old 04-27-2007, 12:22 PM   #4
Registered: Sep 2004
Distribution: Debian Etch
Posts: 45

Original Poster
Rep: Reputation: 15
Yeah, runlevel 2 has network support (is the one I usually use on everyday work). I found out what the problem was: it didn't find the striphtml in the path. I changed the script by adding the absolute path of striphtml instead of the simple name. Thank you anyway


It works now, so that wasn't the problem I can't use ifconfig, because I'm behind a router, and I find this solution easier to implement. Thank you!

Last edited by Uruclef; 04-27-2007 at 12:39 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Firewall - retrieving a live IP address. thekillerbean Linux - Networking 6 02-11-2006 10:22 PM
Shel script mail send ("/" in mail address) problem anaid Linux - Networking 3 08-23-2005 07:41 AM
Perl question: how to insert an e-mail address in a script Pastorino Programming 3 08-08-2005 08:28 AM
Problem retrieving mail using PoP jones139 Linux - Networking 4 06-09-2005 03:10 AM
Exim - piping mail sent to a particular address to a script Khang Linux - Software 2 01-31-2005 11:04 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:28 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration