Click to See Complete Forum and Search --> : startup script?
HairyCane
02-16-2001, 02:58 PM
Just set up my first linux machine, and have a simple question. I am on a corporate network that uses DHCP and I want an easy way to know the IP address assigned when the machine boots. I have an alpha pager with an email address, so my thought was to email myself the IP address once it is known. Anyone know where I can insert the email command line so it happens after the IP address is assigned?
X_console
02-16-2001, 05:09 PM
/etc/rc.d/rc.local should be okay. It's pretty much the last script that runs before the login prompt is presented.
Craig McPherson
02-16-2001, 09:32 PM
Here's a command you can use in your script:
ifconfig eth0 | grep inet | cut -b 21-34 | mail -s "IP Address" you@yourdomain.net
If you want to put IP in the subject of the message instead of the body, you can use two commands, like this:
$MYIP=`ifconfig eth0 | grep inet | cut -b 21-34`
echo "" | mail -s "$MYIP" you@yourdomain.net
HairyCane
02-17-2001, 02:42 PM
Thanks, the rc script worked!
Quick followup. Put the line in the rc file, but i got the email again after I logged in, twice. Is there documentation on when these scripts get executed?
X_console
02-17-2001, 03:03 PM
The rc scripts are executed only every time you switch on your computer or when you reboot. If you put it in your /etc/profile or your ~/.bash_profile then it will be executed everytime you log in, OR if you open up an xterm and pass it the -ls option.