I have an idea for my cable modem issues...

buc99

Don't Tread on Me!
I hope someone out ther that can write Unix scripts can give me a hand with this idea.

Idea:
I would like to write a script that does the following:
1.) It would run ping www.yahoo.com and look for results. Basically,
I've noticed that when my cable connection does not refresh my
dynamic address ping will hang when run from the terminal with
no response. So if this is the case, I would like the script to check for
a response from ping and execute the next item if there is no
response. If there is a response, it would terminate ping and exit.
2.) If no response comes from ping, the script would then enter the
command "shutdown -r now". This would restart the computer and all
of the network settings. This is the only way I know of that works for
resetting my dynamic IP.

The first part is the main hangup for me because I'm not a skilled script writer. With this script written, I could then make it executable and use cron to run the script every 30 minutes or so. This does not fix my cable modem connection problem but would work as a bandaid solution if I have the login set to login automatically. This would then keep my webserver up with minimal interuption. Anyone able to give me some help with this?

Thanks in advance,:)
SA
 
I just had my server hang up. And it did not reboot on it's own. So I tried to run the ping_test script from the terminal and all it does is hang. I copied the script just as you have it written. Is taht supposed to be a "1" in :


result=`ping -c1 www.yahoo.com 2> /dev/null`

The script runs and exits normally when the server is connected to the network, but the script hangs when the network connection goes down. Any more ideas? Is there maybe another approach to this problem? Any help is much appreciated.

Thanks in advance,:)
SA
 
How long did you wait for the script? That ping has to timeout before it fails, so it may take several minutes (probably two, but maybe more).
 
I was mistaken. I think there was an issue with the script and airport. I had been running a software base station off of this server. So when I tried to run the script, it may have hung because it was trying to ping both en0 and en1. After I shut airport off, the computer turned off by itself from the script running in cron. The problem now is, that when the script runs from cron it may be skipping to the "shutdown -r now" section before ping finishes. Because it re-started twice in an hour period just like it should have if the connection was down, but the connection was not down during that time period. So let me ask a stupid question about this script to see if understand how it is working. The script is sending off a packet and asking for a response from www.yahoo.com. It is then using that response to run an if-then statement that will shutdown the computer if there is no response from ping. My question is then, why is the result from ping redirected to /dev/null? Would that not make all $result values empty therefore causing the "shutdown -r now" statement to be executed? Be gentle now, like I said my programing skills are basic so I may not know what I'm talking about.

Next question, since this script relies on the uptime of yahoo's server, could the script be re-written to check ifconfig for a specific IP address, then re-start? The reason I say this is when I check my network preferences during a lost connection I have noticed that my IP has changed from the dynamic IP issued by the cable company to the static IP of the router in the cable modem. If this is the case then ifconfig should list this IP and the $result could be something that reads this number. Just another idea.

Thanks again for everyones help:)
SA
 
Thank you for the re-direct explanation that is helpful. Ok, let me explain my setup now:
I have a Blue Dalmation imac at home acting as my webserver. It is connected to the internet through by en0, my ethernet card, to my cable modem (I think it is a 3com modem, one of the older models). I then have a software base station set up and I have nat setup through my firewall software Brickhouse. This is of course en1. This connection is used by TiBook which is the main computer for most of my work and I don't wish to be tied down to an ethernet connection. The problem I am having is that, like most others have seen with some cable connections, I will lose my dynamic IP generated from my ISP because the imac will not refresh. The cable modem connection to the ISP is still good, but the connection is lost between the cable modem and the imac. The quick fix is to reboot and the connection is re-established between the imac and the cable modem. This has been a big topic on the "Apple complaint lines" yet apple has yet to come up with a software fix for this issue. The only other time I may lose a connection, I say may because it has happened sporadically, is when I shutdown the software base station connection to my TiBook when I'm done working. I do this out of security paranoia. This leads me to believe that there may be another issue between en0 and en1 that is affecting my connection to the cable modem. Since I have absolutely zero support for macs from the cable company, I'm left with the only option of rebooting every so often to re-establish the connection. This is inconvenient if I am at work and the connection goes down and I wish to transfer files from my work computer to my imac at home. So my idea was to get a script that would monitor the network connection and reboot when it was lost then automate it under cron.
(I'm sorry if this is too long)
Now your script seems to be working but it was re-starting my computer every thirty minutes (the crontab was set to run the script as root every thirty minutes) and I'm not sure my connection was lost during the time it was run. So that is why I'm asking about the process of the script. The other thing is, should the script be run as root, or as the user? I've since changed the crontab to run it every 8 hours since my IP usually doesn't refresh IP's until the morning. This will keep my computer from re-starting every 30 minutes. That is why I was asking about ifconfig as an alternate. The cable modem sends out an IP address that is in my network preferences when I lost my internet connection.
Also, the only active network ports on this setup are en0 and en1, I've disabled the modem port. I also have disabled sleep on the imac. I'm getting frustrated with this issue and Apple's response to coming up with a software fix. The only thing I can think of is a script like you wrote to reboot the computer. Any help in this matter is most appreciated.

Thanks,:)
SA
 
Back
Top