#!/bin/bash -x winf="eth1" essid[1]="here"; keys[1]="aabbccddee" essid[0]="AGOLW"; keys[0]="off" essid[2]="default"; keys[2]="off" essid[3]="any"; keys[3]="off" let "maxnet = ${#essid[*]}-1" done=0; for li in $(seq 0 $maxnet) do echo doing net $li if ping -c 1 www.foo.bar || ping -c 1 192.168.1.2 || ping yourserver.example.com # REPLACE these addresses with something meaningful then echo $li : It WORKED worked; >> /var/log/cyclenet break else echo $li : trying ${essid[$li]} >> /var/log/cyclenet killall dhclient3 echo doing net no $li iwconfig $winf essid ${essid[$li]} sleep 3 iwconfig $winf key ${keys[$li]} dhclient3 $winf fi done