Trying to build simple app to notify about changes in small string... Help?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Trying to build simple app to notify about changes in small string... Help?
Hi there!
I'll give a simple explanation about my problem. I'm using ADSL as connection, and I use an external modem/router to connect. Thus, the router takes my WAN IP, and my PC gets a LAN IP which isn't of much use.
I can fetch the WAN IP manually by connecting to the router's internal HTTP server. Anyway, I've created a shell script that outputs the WAN IP into stdout in it's purest form (xxx.xxx.xxx.xxx).
Why did I do this to begin with? Well, simply put, my ISP shifts my IP every now and then, and I'd like to find out when. Thus, I'd like to build a simple application that would use extract the WAN IP every now and then, and notify me and/or log whenever changes occur.
I have close to no programming experience, so I'm basically asking if anyone here can help me out, or point me to some tutorial that I could find useful.
Ok it turns out that it wouldn't have worked (I assumed it did since I got no reply ). This should do it though:
Code:
#!/bin/bash
NEWIP=`lynx -dump http://checkip.dyndns.org | grep "Current IP Address" | awk {'print $4'}`
if [ ! -f ~/mylastip ]; then
echo "NOTHING" > ~/mylastip
fi
OLDIP=`cat ~/mylastip`
if [ "$NEWIP" != "$OLDIP" ]; then
echo $NEWIP > ~/mylastip
# Change the next command to a mail command etc if you want the result mailed to you
echo Your ip address has changed from $OLDIP to $NEWIP
fi
Thanks a lot for the tip! I brought my own small modifications to the script, added it in KCron, and it all seems to be going well!
Code:
#!/bin/sh
function log_notify()
{
NEWIP=`lots of stuff`
if [ ! -f ~/getip.old ]; then
echo "nothing" > ~/getip.old
fi
OLDIP=`cat ~/getip.old`
if [ "$NEWIP" != "$OLDIP" ]; then
echo $NEWIP > ~/getip.old
MSG="IP address has been shifted from $OLDIP to $NEWIP!"
xmessage -center $MSG
LOG="[`date +%Y-%m-%d` `date +%H:%M:%S`] $MSG"
echo $LOG >>~/getip.log
fi
}
function getip()
{
xmessage -center $NEWIP
}
case $1 in
-l|--log)
log_notify
;;
*)
log_notify
getip
;;
esac
Is there any way to build a program in KDevelop or such that could gather data from such shell scripts? Actually, I'm interested in trying to build a simple graphical front-end to my script, where I could eventually add other stuff in and such... But I have no idea where to start.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.