Koozali.org: home of the SME Server

scripting help

Dan Williams

scripting help
« on: February 21, 2003, 11:09:26 PM »
Hi,
I have the need to know when my clients Servers synamic IP changes.
I wrote a little script and put it in cron.weekly to do an ifconfig -a > ipaddress.txt

Then I set up a variable to have it e-mail me the txt file.
It works great.
Not I wondered if it would be easy to create the script to only e-mail me if there is a change in IP. It is over my head, I know what I want, and if anyone can offer assistance or there is an easier way, advice greatly appreciated.
Dan

Mark

Re: scripting help
« Reply #1 on: February 22, 2003, 03:25:38 AM »
I don't know ho to do what you want but i'm urious as to what you did to email the file to yourself?

Mark

Dan Williams

Re: scripting help
« Reply #2 on: February 22, 2003, 05:28:54 AM »
Hi,
This is what I did, don't know if it is right or wrong, but it works.
Made it executeable and put it in cron.daily

# Attempt to create a script that will e-mail
# an administrator daily the ip address of dynamic client.
ifconfig -a > /home/e-smith/files/users/user/home/test/info.txt

# E-mail address the file should be sent to
ADMIN_ADDRESS="your e-mail address here"
#send report to the administrator
/bin/mail -s "Current IP Address" $ADMIN_ADDRESS < /home/e-smith/files/users/dwilliams/home/test/info.txt

Like I said, I am more interested in modifying this to only e-mail me if there is a change.
Dan

Robert

Re: scripting help
« Reply #3 on: February 22, 2003, 02:24:36 PM »
This is the script I use:

#!/bin/sh

for recipients in admin joeuser joeuser@mail.com
do
mail -s "hostname -f now at echo $2" $recipients <As of date -u the external IP of hostname -f is echo $2.
EOF
done

Put it in /etc/e-smith/events/actions/mail-external-ip and do
# ln -s ../actions/mail-external-ip \
/etc/e-smith/events/ip-change/S95mail-external-ip

$2 is the new external IP that ip-change takes as its argument. If you no longer need to be mailed the IP, simply remove the symbolic link from the ip-change event.

Dan

Re: scripting help
« Reply #4 on: February 26, 2003, 07:24:19 PM »
Hi,
I tried this but it did not work for me?

I assumed that the following line should be changed to someone that is in the admin group, so I made it as follows:
"for recipients in admin admin adin@mydomain.com"

I removed the period from the following line?
"As of date -u the external IP of hostname -f is echo $2."

Like I said, I am not very good with scripts, but know what I want.
Any suggestions?

Robert

Re: scripting help
« Reply #5 on: February 26, 2003, 11:30:59 PM »
You actually don't need the for statement. When I wrote the scriptlet I didn't know the syntax for specifying multiple recipients to the mail command, and the for statement was a workaround. Also echo $2 may as well be replaced with $2.
My example had two local recipients, admin and joeuser, and one remote recipient, joeuser@mail.com.
So, if you want your IP sent to local "admin" and remote "user@mail.com", you could use something like:

#!/bin/sh

recipients="admin user@mail.com"
mail -s "hostname -f now at $2" $recipients <As of date the external IP of hostname -f is $2.
EOF

Dan Williams

Re: scripting help
« Reply #6 on: June 26, 2003, 11:43:36 PM »
THis has been working great,
However for the first time something weird happened.
Yesterday one of the servers rebooted, and it did e-mail me, however the ip it e-mailed was still the old ip?
I called the user, had them log into the web server, and look at configuration, and check external ip, and sure enough it was different than what it e-mailed me?
This was 5.6u6?
Any ideas?
dan