Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a device that is only accessible using wireless. By default it starts an ad-hoc wireless I can connect to. The problem is there is no internet access on the ad-hoc.
So I'm connecting it to my router using the commands (its a gnu/linux):

iwconfig ath0 mode managed essid "ESSID"
ifconfig ath0 192.168.1.25 netmask 255.255.255.0 up
route add default gw 192.168.1.1

I want to add it to start up script but I don't want to get locked out of the device forever if something happens to the router (its really old).
Is there any way to check if the connection failed and create an ad-hoc instead if it failed?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Set up the default start up script to use the router. You've already shown how to do that.
Consider router as primary connection.

Make a script, which will be run with crontab every X minutes. The script will ping some Internet address, e.g. 8.8.8.8. In case the ping fails, it will run the script to set up the ad-hoc connection.

Test the settings by shutting down the router.

Only remaining problem is what happens if you somehow make a mistake in your setting? Is there a way to reboot the machine? Or any other option?
In that case, I would consider using some other machine to test the setting, and only when you are sure everything work, copying the setting to the wanted device.

EDIT: to check if bash command is success of a bash command, use $?

For example,

ping 8.8.8.8
if [ $? -eq 0 ]
then
    echo "0 means command success"
else
    echo "non 0 means not success failure, specific commands have exact code for each of failure messages"
fi
share|improve this answer
    
The only way to reset the device is reflash which just deletes everything, I can't do anything else without wireless –  Dani Jul 2 '11 at 20:23
    
Btw, how do I check if a ping fails? –  Dani Jul 2 '11 at 20:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.