Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 netmask up
route add default gw

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
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. 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,

if [ $? -eq 0 ]
    echo "0 means command success"
    echo "non 0 means not success failure, specific commands have exact code for each of failure messages"
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


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.