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.
well, dyndns.org and an update client are too cumbersome so i wrote a script to check to see if my dynamic ip from my isp has changed. if it has changed, i get an text message with the new ip so i can update my dns and continue to ssh to my box at home even if my ip changes. i have the script executed through cron every 5 minutes. is there a better or alternate way to write the script where it is executed every 5 minutes without using cron? i was thinking of using wait, pause, sleep, etc and chkconfig and something that'll verify the process doesn't die. or should i just go ahead and use cron to exectute the script? here's the script.
if [ "$REPLY" == "1" ]; then #Continue if the internet is up
if [ $DYNIP != $DNSIP ]; then #Compare Public IP to DNS IP
echo "$DATE: Email sent at $TIME." >> $LFILE
mail -s $DYNIP $RCPT < . &> /dev/null #Email new Public IP to Recipient
else
exit 0 #Exit if Public IP has not changed
fi
fi
Repetitive tasks are what cron is for - I always use it unless I have a specific reason not to (rare) so I recommend you just schedule it that way.
Was there a specific problem you were having with dyndns? I use it for my home set up with no issues. It has the advantage that I don't need to check my email for an IP address to connect to, I can always just SSH to the domain name.
gotcha. well with the dyndns service, i have to use their domain, i.e. kicks-ass.org and cannot use the one i've already registered unless i pay them. also, i have to install a linux update client to update dyndns whenever my ip changes and i would still need to manually update my zone file with the new ip. i just thought i'd created a script to text me the new ip so i'd know immediately when the ip changed so i could update my zone file quicker. testing has come out fine and i added to the script so it will only run if my connection is up. that way if the internet is down, it won't get confused thinking my ip changed.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Just for reassurance: cron is suitable for such a task. Generally I would use cron for task which run with larger intervals than 2-3 minutes, which is true in your case. For shorter intervals sleep might be better.
I have some scripts running in 10 and 20 seconds intervals for which I use sleep. I never have seen any of my scripts dying for no reason, therefor I have not built in a check to see if the process is alive. Of course you have to take care that you don't create a situation in the script which let the script finalize after encountering an error.
i see. thanks. i was having a problem with the script erroring out with the first if statment when i simulated the internet being down. it was trying to compare "" with "1" and erroring out. so i added the quotes around $REPLY and which resolved the unary problem and if the internet is down, the if statement completes to the last fi and wala, it exits the nested if.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.