|
From: Ivan D. <idr...@us...> - 2006-06-13 20:44:11
|
Update of /cvsroot/terk/embed/src/scripts In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv15314/src/scripts Modified Files: autoconnect.pl getIP.pl scan.pl setHostname.pl showwlan.pl storeUnique.pl tryGateways.pl waitForPing.pl wifiConnect.pl wiredConnect.pl robot.init Log Message: recoverd, seperated embed from cirrus trees Index: showwlan.pl =================================================================== RCS file: /cvsroot/terk/embed/src/scripts/showwlan.pl,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** showwlan.pl 6 Jun 2006 18:31:26 -0000 1.2 --- showwlan.pl 13 Jun 2006 20:44:06 -0000 1.3 *************** *** 3,10 **** #use strict; if(! open WLANCONFIG, "/sbin/wlancfg show wlan0 |"){ ! open(SETLEDS, "/opt/bin/setLEDs 0 |") or die "Cannot set leds $!\n"; ! open(RECONNECT, "/opt/scripts/reconnect.sh |") or die "Cannot set leds $!\n"; ! exit 0; } else { while (<WLANCONFIG>) { --- 3,16 ---- #use strict; + $file = '/opt/connectlog0.txt'; # Log file + open(LOG, ">>$file"); # Open for appending + + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); + + printf LOG "%02d:%02d:%02d ", $hour, $min, $sec; + print LOG "showwlan.pl\n"; + if(! open WLANCONFIG, "/sbin/wlancfg show wlan0 |"){ ! die "Cannot open configfile"; } else { while (<WLANCONFIG>) { *************** *** 22,26 **** $ssid = $WLAN_Configuration{"dot11DesiredSSID"}; ! print "ssid: $ssid \n"; exit 0; --- 28,33 ---- $ssid = $WLAN_Configuration{"dot11DesiredSSID"}; ! print LOG "\tssid: $ssid \n"; + close(LOG); exit 0; Index: wifiConnect.pl =================================================================== RCS file: /cvsroot/terk/embed/src/scripts/wifiConnect.pl,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** wifiConnect.pl 6 Jun 2006 18:31:26 -0000 1.6 --- wifiConnect.pl 13 Jun 2006 20:44:06 -0000 1.7 *************** *** 1,6 **** #!/opt/bin/microperl if(@ARGV != 1){ ! print "Usage is wifiConnect <adapter>\n"; exit; } --- 1,16 ---- #!/opt/bin/microperl + $file = '/opt/connectlog0.txt'; # Log file + open(LOG, ">>$file"); # Open for appending + + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); + + printf LOG "%02d:%02d:%02d ", $hour, $min, $sec; + print LOG "wifiConnect.pl\n"; + + if(@ARGV != 1){ ! print LOG "\tUsage is wifiConnect <adapter>\n"; ! close(LOG); exit; } *************** *** 8,25 **** $INTERFACE = $ARGV[0]; ! print "Connecting on $INTERFACE...\n"; ! open (CONFIG, "<", "/opt/config.$INTERFACE") or die "Cannot open configfile: $!"; ! while (<CONFIG>) { ! chomp; ! s/#.*//; ! s/^\s+//; ! s/\+$//; ! open(LEDS, "/opt/bin/setLEDs 0|") or die "Cannot set leds $!\n"; ! sleep .2; ! open(LEDS, "/opt/bin/setLEDs 0 1|") or die "Cannot set leds $!\n"; ! next unless length; ! my ($var, $value) = split(/\s*=\s*/, $_, 2); ! $Config{$var} = $value; } --- 18,35 ---- $INTERFACE = $ARGV[0]; ! print LOG "\tConnecting on $INTERFACE...\n"; ! if(! open CONFIG, "<", "/opt/config.$INTERFACE"){ ! die "Cannot open configfile: $!"; ! } else { ! while (<CONFIG>) { ! chomp; ! s/#.*//; ! s/^\s+//; ! s/\+$//; ! next unless length; ! my ($var, $value) = split(/\s*=\s*/, $_, 2); ! $Config{$var} = $value; ! } } *************** *** 27,72 **** $networkKey = $Config{"networkKey"}; ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} lnxreq_ifstate ifstate=enable |") or die "wlanctl-ng failed $!\n"; ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} dot11req_mibset mibattribute=p2CnfShortPreamble=long |") or die "wlanctl-ng failed $!\n"; if ($Config{"auto"} =~ m/true/){ ! print "Using autoconnect\n"; open(SCAN, "/opt/scripts/scan.pl |") or die "Cannot run scan.pl $!\n"; - - sleep 2; - open(AUTOCONNECT, "/opt/scripts/autoconnect.pl |") or die "Cannot run autoconnect.pl $!\n"; while(<AUTOCONNECT>){ chomp; ! print "$_ \n"; } } else { if($Config{"dataEncryption"} =~ m/wep/){ ! print "Connecting using encryption to $ssid\n"; ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} dot11req_mibset mibattribute=dot11WEPDefaultKey=$networkKey |") or die "wlanctl-ng failed $!\n"; ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} dot11req_mibset mibattribute=dot11WEPDefaultKeyID=0 |") or die "wlanctl-ng failed $!\n"; ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} dot11req_mibset mibattribute=dot11ExcludeUnencrypted=true |") or die "wlanctl-ng failed $!\n"; ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} lnxreq_autojoin ssid=$ssid authtype=opensystem |") or die "wlanctl-ng failed $!\n"; } else { ! print "Connecting unencrypted to $ssid\n"; ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} lnxreq_autojoin ssid=$ssid authtype=opensystem |") or die "wlanctl-ng failed $!\n"; ! while(<WLANCTL>){ ! print "$_"; ! } ! open (RENEW, "/sbin/udhcpc -nq -i $INTERFACE|") or die "udhcpc failed $!\n"; ! while(<RENEW>){ ! print $_; ! } } ! ! open(SETLEDS,"/opt/bin/setLEDs 0 1 |") or die "Cannot set leds.\n"; } ! open(SETHOSTNAME, "/opt/scripts/setHostname.pl wlan0 |") or die "Failed to set host\name\ $!\n"; ! while(<SETHOSTNAME>){ ! print $_; ! } --- 37,73 ---- $networkKey = $Config{"networkKey"}; ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} lnxreq_ifstate ifstate=enable |"); ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} dot11req_mibset mibattribute=p2CnfShortPreamble=long |"); ! if ($Config{"auto"} =~ m/true/){ ! print LOG "\tUsing autoconnect\n"; open(SCAN, "/opt/scripts/scan.pl |") or die "Cannot run scan.pl $!\n"; open(AUTOCONNECT, "/opt/scripts/autoconnect.pl |") or die "Cannot run autoconnect.pl $!\n"; while(<AUTOCONNECT>){ chomp; ! print LOG "\t$_ \n"; } } else { if($Config{"dataEncryption"} =~ m/wep/){ ! print LOG "\tConnecting using encryption to $ssid\n"; ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} dot11req_mibset mibattribute=dot11WEPDefaultKey=$networkKey |"); ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} dot11req_mibset mibattribute=dot11WEPDefaultKeyID=0 |"); ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} dot11req_mibset mibattribute=dot11ExcludeUnencrypted=true |"); ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} lnxreq_autojoin ssid=$ssid authtype=opensystem |"); } else { ! print LOG "\tConnecting unencrypted to $ssid\n"; ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} lnxreq_autojoin ssid=$ssid authtype=opensystem |"); } ! # open(SETLEDS, "/opt/bin/setLEDs 0 1 2 3 4 5|"); ! # sleep 1; ! # open(SETLEDS, "/opt/bin/setLEDs 0|"); ! # sleep 1; ! # open(SETLEDS, "/opt/bin/setLEDs 0 1 2 3 4 5|"); } ! close(LOG); Index: wiredConnect.pl =================================================================== RCS file: /cvsroot/terk/embed/src/scripts/wiredConnect.pl,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** wiredConnect.pl 26 May 2006 22:05:29 -0000 1.4 --- wiredConnect.pl 13 Jun 2006 20:44:06 -0000 1.5 *************** *** 1,9 **** #!/opt/bin/microperl ! #$RELAY_IP = "128.2.211.159"; ! $RELAY_IP = "lion-o.terk.ri.cmu.edu"; if(@ARGV != 1){ ! print "Usage is wiredConnect <adapter>\n"; exit; } --- 1,15 ---- #!/opt/bin/microperl ! $file = '/opt/connectlog0.txt'; # Log file ! open(LOG, ">>$file"); # Open for appending ! ! ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); ! ! printf LOG "%02d:%02d:%02d ", $hour, $min, $sec; ! print LOG "wiredConnect.pl\n"; if(@ARGV != 1){ ! print LOG "\tUsage is wiredConnect <adapter>\n"; ! close(LOG); exit; } *************** *** 11,75 **** $INTERFACE = $ARGV[0]; ! open (CONFIG, "<", "/opt/config.$INTERFACE") or die "Cannot open configfile: $!"; ! while (<CONFIG>) { ! chomp; ! s/#.*//; ! s/^\s+//; ! s/\+$//; ! next unless length; ! $value = lc($value); ! my ($var, $value) = split(/\s*=\s*/, $_, 2); ! $Config{$var} = $value; } if($Config{"useDHCP"} =~ /true/){ ! print "Connecting on $INTERFACE using dhcp\n"; ! open (RENEW, "/sbin/udhcpc -nq -i $INTERFACE|") or die "udhcpc failed $!\n"; while(<RENEW>){ ! print $_; } ! open(IPGRAB, "/opt/scripts/getIP.pl $INTERFACE |") or die "getIP failed $!\n"; while(<IPGRAB>){ ! print $_; $ip = $_; } - if($ip){ - print "Registered on: $ip \n"; - print "Trying to ping relay... \n"; - - ($successes, $max_delay) = ping($RELAY_IP, 4); - - if($successes > 0){ - print "We had some successes pinging, yeah! Exiting\n"; - open(SETHOSTNAME, "/opt/scripts/setHostname.pl $INTERFACE |") or die "Failed to set hostname $!\n"; - while(<SETHOSTNAME>){ - print $_; - } - exit 0; - } else { - print "Ping failed, removing route.\n"; - - open (ROUTES, "/bin/netstat -nr |") or die "Cannot netstat $!\n"; - - while(<ROUTES>){ - chomp; - ($Destination, $Gateway, $Genmask, $Flags, $MSS, $Window, $irtt, $Iface) = split(); - if($Flags =~ m/UG/){ - print "$Gateway is a gateway on $Iface\n"; - $Gateways{$Iface} = $Gateway; - } - } - - open(DELROUTE, "/sbin/route del default gw $Gateways{$INTERFACE} |") or die "Failed to delete route $!\n"; - print "Removing gateway on $INTERFACE\n"; - print "/sbin/route del default gw $Gateways{$INTERFACE}\n"; - } - } else { - print "DHCP failed, setting to default static IP of 192.168.1.144 and mask of 255.255.255.0\n"; - open(IFCONFIG, "/sbin/ifconfig $INTERFACE 192.168.1.144 netmask 255.255.255.0 |") or die "ifconfig failed $!\n"; - } - } else { $ip = $Config{"address"}; --- 17,49 ---- $INTERFACE = $ARGV[0]; ! if(! open CONFIG, "<", "/opt/config.$INTERFACE"){ ! die "Cannot open configfile: $!"; ! } else { ! while (<CONFIG>) { ! chomp; ! s/#.*//; ! s/^\s+//; ! s/\+$//; ! next unless length; ! $value = lc($value); ! my ($var, $value) = split(/\s*=\s*/, $_, 2); ! $Config{$var} = $value; ! } } if($Config{"useDHCP"} =~ /true/){ ! print LOG "\tConnecting on $INTERFACE using dhcp\n"; ! open (RENEW, "/sbin/udhcpc -nq -i $INTERFACE|"); while(<RENEW>){ ! print LOG $_; } ! open(IPGRAB, "/opt/scripts/getIP.pl $INTERFACE |"); while(<IPGRAB>){ ! print LOG $_; $ip = $_; } + print LOG "\tRegistered on: $ip \n"; } else { $ip = $Config{"address"}; *************** *** 77,125 **** $gateway = $Config{"gateway"}; ! print "Connecting on $INTERFACE using static IP $ip\n"; ! open(IFCONFIG, "/sbin/ifconfig $INTERFACE $ip netmask $mask |") or die "ifconfig failed $!\n"; if($gateway){ ! print "Using gateway: $gateway\n"; ! open(GATEWAY, "/sbin/route add default gw $gateway |") or die "route add failed $!\n"; ! } ! } ! ! sub ping{ ! my $ip = $_[0]; ! my $attempts = $_[1]; ! # print "/bin/ping -c $attempts $ip \n"; ! open (PING, "/bin/ping -c $attempts $ip |") or die "ping failed $!\n";; ! ! while (<PING>) { ! # print "$_"; ! if (/^(\d+) packets transmitted, (\d+) /) { ! $pkts_sent = $1; ! $pkts_rcvd = $2; ! } ! elsif (/(\d+\.?\d*)\/(\d+\.?\d*)\/(\d+\.?\d*)/) { #look for num/num/num ! $min = $1; ! $avg = $2; ! $max = $3; ! } ! elsif (/^(\d+).*seq=(\d+).*ttl=(\d+).*time=(\d+\.?\d*) ms/) { ! # look for packet size seq=NN and time=NN ! $pkt_size[$pingI]=$1; ! $seq[$pingI]=$2; ! $ttl[$pingI]=$3; ! $rtt[$pingI]=$4; ! $pingI++; ! } elsif (/^(\d+).*seq=(\d+).*ttl=(\d+).*time=(\d+\.?\d*) usec/) { ! # look for packet size seq=NN and time=NN ! $pkt_size[$pingI]=$1; ! $seq[$pingI]=$2; ! $ttl[$pingI]=$3; ! $rtt[$pingI]=$4/1000; ! $pingI++; ! } ! elsif( /^interval: (\d+\.?\d*)/ ) { ! $interval = $1; ! } } - close (PING); - return ($pkts_rcvd, $max); } --- 51,59 ---- $gateway = $Config{"gateway"}; ! print LOG "\tConnecting on $INTERFACE using static IP $ip\n"; ! open(IFCONFIG, "/sbin/ifconfig $INTERFACE $ip netmask $mask |"); if($gateway){ ! print LOG "\tUsing gateway: $gateway\n"; ! open(GATEWAY, "/sbin/route add default gw $gateway |"); } } Index: storeUnique.pl =================================================================== RCS file: /cvsroot/terk/embed/src/scripts/storeUnique.pl,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** storeUnique.pl 19 Apr 2006 22:55:20 -0000 1.1 --- storeUnique.pl 13 Jun 2006 20:44:06 -0000 1.2 *************** *** 1,4 **** --- 1,12 ---- #!/opt/bin/microperl + $file = '/opt/connectlog0.txt'; # Log file + open(LOG, ">>$file"); # Open for appending + + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); + + printf LOG "%02d:%02d:%02d ", $hour, $min, $sec; + print LOG "storeUnique.pl\n"; + open(UNIQID, "/opt/bin/devmem 0x80832440 w |") or die "Cannot run devmem $!\n"; *************** *** 33,35 **** #print "$unique $random \n"; ! print IDFILE "$unique $random\n"; --- 41,46 ---- #print "$unique $random \n"; ! print LOG "\tsaving id and pass to file\n"; ! print IDFILE "$unique\n$random\n"; ! ! close(LOG); Index: setHostname.pl =================================================================== RCS file: /cvsroot/terk/embed/src/scripts/setHostname.pl,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** setHostname.pl 19 Apr 2006 20:46:24 -0000 1.1 --- setHostname.pl 13 Jun 2006 20:44:06 -0000 1.2 *************** *** 1,4 **** --- 1,11 ---- #!/opt/bin/microperl + $file = '/opt/connectlog0.txt'; # Log file + open(LOG, ">>$file"); # Open for appending + + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); + + printf LOG "%02d:%02d:%02d ", $hour, $min, $sec; + print LOG "setHostname.pl\n"; sub ifconfig2list() *************** *** 150,158 **** my($interfaceName) = shift; my(%interface) = %{$allInterfaces{$interfaceName}}; ! print "\n $interfaceName \n"; my($key,$value); ! print "\n\n[$interfaceName]======================================\n"; foreach $key (sort(keys(%interface))){ ! print "$key=" . $interface{$key} . "\n"; } } --- 157,165 ---- my($interfaceName) = shift; my(%interface) = %{$allInterfaces{$interfaceName}}; ! print LOG "\n\t $interfaceName \n"; my($key,$value); ! print LOG "\n\n\t[$interfaceName]======================================\n"; foreach $key (sort(keys(%interface))){ ! print LOG "\t$key=" . $interface{$key} . "\n"; } } *************** *** 177,181 **** if(@ARGV != 1){ ! print "Usage is setHostname <adapter>\n"; exit; } --- 184,189 ---- if(@ARGV != 1){ ! print LOG "\tUsage is setHostname <adapter>\n"; ! close (LOG); exit; } *************** *** 186,190 **** $hostname = getKey(%interfaces, $ARGV[0], "a_inet"); ! print "setting hostname to $hostname\n"; open(SETHOSTNAME, "/bin/hostname $hostname |") or die "Cannot run hostname $!\n"; --- 194,200 ---- $hostname = getKey(%interfaces, $ARGV[0], "a_inet"); ! print LOG "\tsetting hostname to $hostname\n"; open(SETHOSTNAME, "/bin/hostname $hostname |") or die "Cannot run hostname $!\n"; + + close(LOG); Index: waitForPing.pl =================================================================== RCS file: /cvsroot/terk/embed/src/scripts/waitForPing.pl,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** waitForPing.pl 6 Jun 2006 18:31:26 -0000 1.5 --- waitForPing.pl 13 Jun 2006 20:44:06 -0000 1.6 *************** *** 1,10 **** #!/opt/bin/microperl ! $RELAY_IP = "128.2.211.159"; $MAX_ATTEMPTS = 4; if(@ARGV != 1){ ! print "Usage is waitForPing <address>\n"; exit; } --- 1,19 ---- #!/opt/bin/microperl ! #require 'getIPlib.pl'; ! ! $file = '/opt/connectlog0.txt'; # Log file ! open(LOG, ">>$file"); # Open for appending ! ! ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); ! ! printf LOG "%02d:%02d:%02d ", $hour, $min, $sec; ! print LOG "waitForPing.pl\n"; $MAX_ATTEMPTS = 4; if(@ARGV != 1){ ! print LOG "\tUsage is waitForPing <address>\n"; ! close(LOG); exit; } *************** *** 15,94 **** $pkts_rcvd = 0; ! while(($successes == 0) && ($counter < $MAX_ATTEMPTS)){ # print "Trying to ping $IP\n"; ! if(($counter % 2 ) == 0){ ! open(LED, "/opt/bin/setLEDs 0 |") or die "Cannot set LED $!\n"; ! } else { ! open(LED, "/opt/bin/setLEDs 0 1 |") or die "Cannot set LED $!\n"; ! } ! ! ($successes, $max_delay) = ping($RELAY_IP, 4); ! ! $counter++; ! } ! ! if($counter < $MAX_ATTEMPTS){ ! print "pinged $IP succesfully after $counter attempts\n"; ! open(LED, "/opt/bin/setLEDs 0 1 6|") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 6|") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 1 |") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 |") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 1 6|") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 6|") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 1 |") or die "Cannot set LED $!\n"; ! } ! else{ ! print "failed to ping $IP, giving up\n"; ! #Blink ERROR no. 4 ! open(LED, "/opt/bin/setLEDs 0 1 7|") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 7|") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 1 |") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 |") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 1 7|") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 7|") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 1 |") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 |") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 1 7|") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 7|") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 1 |") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 |") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 1 7|") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 7|") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 1 |") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 |") or die "Cannot set LED $!\n"; ! ! # print "failed to ping $IP, trying different gateway configurations..\n"; ! # open(TRYGATEWAYS, "/opt/scripts/tryGateways.pl |"); ! } ! sub ping{ ! my $ip = $_[0]; ! my $attempts = $_[1]; ! # print "/bin/ping -c $attempts $ip \n"; ! open (PING, "/bin/ping -c $attempts $ip |") or die "ping failed $!\n";; while (<PING>) { ! # print "$_"; if (/^(\d+) packets transmitted, (\d+) /) { $pkts_sent = $1; --- 24,42 ---- $pkts_rcvd = 0; ! while(($pkts_rcvd == 0) && ($counter < $MAX_ATTEMPTS)){ # print "Trying to ping $IP\n"; ! # if(($counter % 2 ) == 0){ ! # open(LED, "/opt/bin/setLEDs 0 1 2 3 4 5 6|") or die "Cannot set LED $!\n"; ! # } else { ! # open(LED, "/opt/bin/setLEDs 0 1 2 3 4 5|") or die "Cannot set LED $!\n"; ! # } ! open (PING, "/bin/ping -c 1 $IP |"); ! $pkts_rcvd = 0; ! $pkts_sent = 0; ! $max = 0; while (<PING>) { ! # print LOG "$_"; if (/^(\d+) packets transmitted, (\d+) /) { $pkts_sent = $1; *************** *** 120,124 **** } close (PING); ! return ($pkts_rcvd, $max); } --- 68,84 ---- } close (PING); ! ! $counter++; } + if($counter < $MAX_ATTEMPTS){ + print LOG "\tpinged $IP succesfully after $counter attempts\n"; + + # open(LED, "/opt/bin/setLEDs 0 1 2 3 4 5 6 7|") or die "Cannot set LED $!\n"; + open(TRYGATEWAYS, "/opt/scripts/tryGateways.pl |"); + + } + else{ + print LOG "\tfailed to ping $IP, trying different gateway configurations..\n"; + open(TRYGATEWAYS, "/opt/scripts/tryGateways.pl |"); + } Index: robot.init =================================================================== RCS file: /cvsroot/terk/embed/src/scripts/robot.init,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** robot.init 6 Jun 2006 18:31:26 -0000 1.20 --- robot.init 13 Jun 2006 20:44:06 -0000 1.21 *************** *** 1,92 **** #!/bin/sh ! #Stage 0: Robot Configuration and Setup ! /opt/bin/setLEDs ! mv /opt/connectlog3.txt /opt/connectlog4.txt #Copy Logs ! /opt/bin/setLEDs 0 mv /opt/connectlog2.txt /opt/connectlog3.txt - /opt/bin/setLEDs mv /opt/connectlog1.txt /opt/connectlog2.txt - /opt/bin/setLEDs 0 mv /opt/connectlog0.txt /opt/connectlog1.txt ! /opt/bin/setLEDs ! echo `date +%R:%S` Generating robot ID... >> /opt/connectlog0.txt #Create ID ! /opt/bin/setLEDs 0 ! /opt/scripts/storeUnique.pl ! /opt/bin/setLEDs ! ! echo `date +%R:%S` Creating video device... >> /opt/connectlog0.txt #Mount Video ! /opt/bin/setLEDs 0 ! mknod /dev/video0 c 81 0 >> /opt/connectlog0.txt ! /opt/bin/setLEDs ! ! echo `date +%R:%S` Loading prism2_usb... >> /opt/connectlog0.txt #Mount USB ! /opt/bin/setLEDs 0 ! modprobe prism2_usb >> /opt/connectlog0.txt ! /opt/bin/setLEDs echo `date +%R:%S` Uploading fpga bitstream... >> /opt/connectlog0.txt #Configure FPGA - /opt/bin/setLEDs 0 /opt/fpga/fpgac /opt/fpga/qwerk.bit >> /opt/connectlog0.txt - /opt/bin/setLEDs echo `date +%R:%S` Loading Qwerk modules... >> /opt/connectlog0.txt #Mount QWERK Drivers - /opt/bin/setLEDs 0 insmod /opt/drivers/qeinterrupt.ko >> /opt/connectlog0.txt - /opt/bin/setLEDs insmod /opt/drivers/qemotor.ko >> /opt/connectlog0.txt - /opt/bin/setLEDs 0 echo `date +%R:%S` Linking web pages... >> /opt/connectlog0.txt #Link Webpages - /opt/bin/setLEDs rm /home/www/html - /opt/bin/setLEDs 0 rm /home/www/index.html - /opt/bin/setLEDs - - ln -s /opt/www/index.html /home/www/index.html - /opt/bin/setLEDs 0 - ln -s /opt/www/menu.html /home/www/menu.html - /opt/bin/setLEDs ln -s /opt/www/loglinks.html /home/www/loglinks.html - /opt/bin/setLEDs 0 - ln -s /opt/www/html /home/www/html - /opt/bin/setLEDs ! ln -s /opt/www/cgi-bin /home/www/cgi-bin ! /opt/bin/setLEDs 0 ! ln -s /opt/www/files /home/www/files ! /opt/bin/setLEDs ! ln -s /opt/connectlog0.txt /home/www/connectlog0.txt ! /opt/bin/setLEDs 0 ! ln -s /opt/connectlog1.txt /home/www/connectlog1.txt ! /opt/bin/setLEDs ! ! ln -s /opt/connectlog2.txt /home/www/connectlog2.txt ! /opt/bin/setLEDs 0 ! ln -s /opt/connectlog3.txt /home/www/connectlog3.txt ! /opt/bin/setLEDs ! ln -s /opt/connectlog4.txt /home/www/connectlog4.txt ! /opt/bin/setLEDs 0 ! echo `date +%R:%S` Checking for CFG button... >> /opt/connectlog0.txt #Check CFG ! /opt/bin/setLEDs ! /opt/bin/checkCFG ! /opt/bin/setLEDs 0 ! echo `date +%R:%S` Connecting to the wired network... >> /opt/connectlog0.txt ! /opt/bin/setLEDs ! /opt/scripts/wiredConnect.pl eth0 >> /opt/connectlog0.txt ! /opt/bin/setLEDs 0 - echo `date +%R:%S` Mounting nfs... >> /opt/connectlog0.txt #Mount NFS - /opt/bin/setLEDs - mount -t nfs -o nolock 192.168.1.103:/edbnfs /mnt >> /opt/connectlog0.txt - /opt/bin/setLEDs 0 - #Stage 1 & 2: Connect - /opt/scripts/reconnect.sh - exit 0 --- 1,80 ---- #!/bin/sh ! #################### Stage 0.0: Logs and basic Hardware ############################################ ! ! /opt/bin/setLEDs ! ! mv /opt/connectlog3.txt /opt/connectlog4.txt #Copy Logs mv /opt/connectlog2.txt /opt/connectlog3.txt mv /opt/connectlog1.txt /opt/connectlog2.txt mv /opt/connectlog0.txt /opt/connectlog1.txt ! echo `date +%R:%S` Copied logs. >> /opt/connectlog0.txt echo `date +%R:%S` Uploading fpga bitstream... >> /opt/connectlog0.txt #Configure FPGA /opt/fpga/fpgac /opt/fpga/qwerk.bit >> /opt/connectlog0.txt echo `date +%R:%S` Loading Qwerk modules... >> /opt/connectlog0.txt #Mount QWERK Drivers insmod /opt/drivers/qeinterrupt.ko >> /opt/connectlog0.txt insmod /opt/drivers/qemotor.ko >> /opt/connectlog0.txt + #################### Stage 0.1: Generate Unique mubers, checking for CFG ########################### + + echo `date +%R:%S` Generating robot ID... >> /opt/connectlog0.txt #Create ID + /opt/scripts/storeUnique.pl + + echo `date +%R:%S` Checking for CFG button... >> /opt/connectlog0.txt #Check CFG + /opt/bin/checkCFG + + #################### Stage 0.2: Webpages and Misc Devices ######################################### + + /opt/bin/setLEDs 0 + echo `date +%R:%S` Loading prism2_usb... >> /opt/connectlog0.txt #Mount USB + modprobe prism2_usb >> /opt/connectlog0.txt + + /opt/bin/setLEDs + echo `date +%R:%S` Creating video device... >> /opt/connectlog0.txt #Mount Video + mknod /dev/video0 c 81 0 >> /opt/connectlog0.txt + + /opt/bin/setLEDs 0 echo `date +%R:%S` Linking web pages... >> /opt/connectlog0.txt #Link Webpages rm /home/www/html rm /home/www/index.html + /opt/bin/setLEDs + ln -s /opt/www/index.html /home/www/index.html + ln -s /opt/www/menu.html /home/www/menu.html + ln -s /opt/www/tcpip.html /home/www/tcpip.html ln -s /opt/www/loglinks.html /home/www/loglinks.html ! /opt/bin/setLEDs 0 ! ln -s /opt/www/html /home/www/html ! ln -s /opt/www/cgi-bin /home/www/cgi-bin ! ln -s /opt/www/files /home/www/files ! /opt/bin/setLEDs 1 ! ln -s /opt/connectlog0.txt /home/www/connectlog0.txt ! ln -s /opt/connectlog1.txt /home/www/connectlog1.txt ! ln -s /opt/connectlog2.txt /home/www/connectlog2.txt ! ln -s /opt/connectlog3.txt /home/www/connectlog3.txt ! ln -s /opt/connectlog4.txt /home/www/connectlog4.txt ! #################### Stage 1 & 2: Network Connect##################################################### ! /opt/bin/setLEDs ! ! /opt/scripts/wifiConnect.pl wlan0 >> /opt/connect.log ! /opt/scripts/wiredConnect.pl eth0 >> /opt/connect.log ! ! udhcpc -i wlan0 -b -p /var/run/udhcpc.wlan0 >/dev/null 2>&1 >> /opt/connect.log ! ! mount -t nfs -o nolock 192.168.1.103:/edbnfs /mnt >> /opt/connect.log ! ! sleep 5; ! ! /opt/scripts/waitForPing.pl 128.2.211.159 >> /opt/connect.log ! ! cd /opt/ice ! /opt/ice/terkServer & Index: scan.pl =================================================================== RCS file: /cvsroot/terk/embed/src/scripts/scan.pl,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** scan.pl 14 Apr 2006 16:08:05 -0000 1.1 --- scan.pl 13 Jun 2006 20:44:06 -0000 1.2 *************** *** 1,4 **** --- 1,12 ---- #!/opt/bin/microperl + $file = '/opt/connectlog0.txt'; # Log file + open(LOG, ">>$file"); # Open for appending + + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); + + printf LOG "%02d:%02d:%02d ", $hour, $min, $sec; + print LOG "scan.pl\n"; + open(SCAN, "/sbin/wlanctl-ng wlan0 dot11req_scan bsstype=infrastructure bssid=ff:ff:ff:ff:ff:ff ssid= scantype=active probedelay=100 channellist=01:02:03:04:05:06:07:08:09:0a:0b:0c:0d:0e minchanneltime=10 maxchanneltime=100 |") or die "Cannot run scan: $!\n"; *************** *** 16,22 **** $resultcode = $SCAN_results{"resultcode"}; ! print "result code is $resultcode\n"; close(SCAN); exit 0; --- 24,32 ---- $resultcode = $SCAN_results{"resultcode"}; ! print LOG "\tresult code is $resultcode\n"; close(SCAN); + close(LOG); + exit 0; Index: autoconnect.pl =================================================================== RCS file: /cvsroot/terk/embed/src/scripts/autoconnect.pl,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** autoconnect.pl 6 Jun 2006 18:31:26 -0000 1.11 --- autoconnect.pl 13 Jun 2006 20:44:06 -0000 1.12 *************** *** 0 **** --- 1,240 ---- + #!/opt/bin/microperl + + #use strict; + + $file = '/opt/connectlog0.txt'; # Log file + open(LOG, ">>$file"); # Open for appending + + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); + + #printf "%02d:%02d:%02d\n", + #$hour,$min,$sec; + + printf LOG "%02d:%02d:%02d ", $hour, $min, $sec; + print LOG "autoconnect.pl\n"; + + open(CHECKFORWLAN, "/sbin/ifconfig wlan0 2>&1 |") or die "Cannot run ifconfig wlan0 $!\n"; + + while(<CHECKFORWLAN>) { + if($_ =~ m/\berror\b/) { + print LOG "\tNo wlan0!\n"; + print LOG "\t$_\n"; + #open(LED, "/opt/bin/setLEDs 0 1 2 3 4 5 6 7 |") or die "Cannot set LED $!\n"; + #sleep 1; + #open(LED, "/opt/bin/setLEDs |") or die "Cannot set LED $!\n"; + #sleep 1; + #open(LED, "/opt/bin/setLEDs 0 1 2 3 4 5 6 7 |") or die "Cannot set LED $!\n"; + #sleep 1; + #open(LED, "/opt/bin/setLEDs |") or die "Cannot set LED $!\n"; + close(LOG); + exit; + } + } + + #open(LED, "/opt/bin/setLEDs 0 |") or die "Cannot set LED $!\n"; + + print LOG "\tTrying the various access points:\n"; + + for ($index = 0; $index < 16; $index++){ + open (RESULTS, "/sbin/wlanctl-ng wlan0 dot11req_scan_results bssindex=$index |") or die "Cannot open results: $!\n"; + while (<RESULTS>) { + chomp; + s/#.*//; + s/^\s+//; + s/\+$//; + next unless length; + my ($var, $value) = split(/\s*=\s*/, $_, 2); + $value =~ tr/'//d; + $Results[$index] {$var} = $value; + } + + close RESULTS; + + $ssid = $Results[$index]{ssid}; + $noise = $Results[$index]{noise} - 65400; + $signal = $Results[$index]{signal} - 65400; + $bssid = $Results[$index]{bssid}; + + $connect_success = 0; + + print LOG "\tbssid: $bssid ssid: $ssid\n"; + + if($ssid eq "no_value"){ + } else { + #open(LED, "/opt/bin/setLEDs|") or die "Cannot set LED $!\n"; + #sleep .2; + #open(LED, "/opt/bin/setLEDs 0|") or die "Cannot set LED $!\n"; + + open (CONNECT, "/sbin/wlanctl-ng wlan0 lnxreq_autojoin ssid=$ssid authtype=opensystem |") or die "Cannot open connect $!\n"; + + while (<CONNECT>) { + chomp; + s/#.*//; + s/^\s+//; + s/\+$//; + next unless length; + my ($var, $value) = split(/\s*=\s*/, $_, 2); + $value =~ tr/'//d; + $CONNECT_Result{$var} = $value; + # print LOG "\tvar $var is $value\n"; + } + + close CONNECT; + + open(PSAUX, "/bin/ps |") or die "Cannot run /bin/ps $!\n"; + while(<PSAUX>) { + if($_ =~ /wlan0/ && $_ =~ /udhcpc/){ + chomp; + @entry = split(' '); + $pid = $entry[0]; + print LOG "\tkilling udhcpc pid $pid\n"; + open (KILLUDHCPC, "/bin/kill $pid |") or die "Cannot kill udhcpc $!\n"; + } + } + + + sleep 1; + open (RENEW, "/sbin/udhcpc -nq -i wlan0|") or die "Cannot send renew signal to udhcpc $!\n"; + # open (RENEW, "/bin/kill -SIGUSR1 $pid |") or die "Cannot send renew signal to udhcpc $!\n"; + sleep 1; + + open(IPGRAB, "/opt/scripts/getIP.pl wlan0 |"); + while(<IPGRAB>){ + chomp; + $ip = $_; + } + + $pkts_sent = 0; + $pkts_rcvd = 0; + $max = 0; + + if($ip){ + print LOG "\tGot: $ip \n"; + + open (PING, "/bin/ping -c 4 128.2.211.159 |"); + + while (<PING>) { + # print "$_"; + if (/^(\d+) packets transmitted, (\d+) /) { + $pkts_sent = $1; + $pkts_rcvd = $2; + } + elsif (/(\d+\.?\d*)\/(\d+\.?\d*)\/(\d+\.?\d*)/) { #look for num/num/num + $min = $1; + $avg = $2; + $max = $3; + } + elsif (/^(\d+).*seq=(\d+).*ttl=(\d+).*time=(\d+\.?\d*) ms/) { + # look for packet size seq=NN and time=NN + $pkt_size[$pingI]=$1; + $seq[$pingI]=$2; + $ttl[$pingI]=$3; + $rtt[$pingI]=$4; + $pingI++; + } elsif (/^(\d+).*seq=(\d+).*ttl=(\d+).*time=(\d+\.?\d*) usec/) { + # look for packet size seq=NN and time=NN + $pkt_size[$pingI]=$1; + $seq[$pingI]=$2; + $ttl[$pingI]=$3; + $rtt[$pingI]=$4/1000; + $pingI++; + } + elsif( /^interval: (\d+\.?\d*)/ ) { + $interval = $1; + } + } + close (PING); + + print LOG "\tpackets sent: $pkts_sent packets received: $pkts_rcvd\n"; + print LOG "\tmax response time was: $max\n"; + } + + if($pkts_rcvd == 0){ + $Results[$index]{ping_success} = "bad "; + } else { + $Results[$index]{ping_success} = "good"; + } + + $Results[$index]{pkts_rcvd} = $pkts_rcvd; + } + } + + @ordered = sort { $b->{pkts_rcvd} <=> $a->{pkts_rcvd} || $b->{signal} <=> $a->{signal} } @Results; + + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); + + printf LOG "\n\t%02d:%02d:%02d ", $hour, $min, $sec; + print LOG "Results in order of preference: \n\n"; + + for $ref (@ordered){ + $ossid = $ref->{ssid}; + $obssid = $ref->{bssid}; + $opkts_rcvd = $ref->{pkts_rcvd}; + $osignal = $ref->{signal} - 65400; + $onoise = $ref->{noise} - 65400; + print LOG "\t$obssid $opkts_rcvd $osignal $onoise $ossid\n"; + } + + $best_ssid = $ordered[0]{ssid}; + + if($ordered[0]{ping_success} eq "good"){ + #open(LED, "/opt/bin/setLEDs 0 1 |") or die "Cannot set LED $!\n"; + + print LOG "\tConnecting to ssid: $best_ssid\n"; + + open (FINAL_CONNECT, "/sbin/wlanctl-ng wlan0 lnxreq_autojoin ssid=$best_ssid authtype=opensystem |") or die "Cannot open connect $!\n"; + + while (<FINAL_CONNECT>) { + chomp; + s/#.*//; + s/^\s+//; + s/\+$//; + next unless length; + my ($var, $value) = split(/\s*=\s*/, $_, 2); + $value =~ tr/'//d; + $FINAL_CONNECT_Result{$var} = $value; + # print "var $var is $value\n"; + } + + open(PSAUX, "/bin/ps |") or die "Cannot run /bin/ps $!\n"; + while(<PSAUX>) { + if($_ =~ /wlan0/ && $_ =~ /udhcpc/){ + chomp; + @entry = split(' '); + $pid = $entry[0]; + print LOG "\tkilling udhcpc pid $pid\n"; + open (KILLUDHCPC, "/bin/kill $pid |") or die "Cannot kill udhcpc $!\n"; + } + } + + if($FINAL_CONNECT_Result{resultcode} eq "success"){ + print LOG "\tSuccessfully connected\n"; + + #open(LED, "/opt/bin/setLEDs 0|") or die "Cannot set LED $!\n"; + #sleep .2; + #open(LED, "/opt/bin/setLEDs 0 1|") or die "Cannot set LED $!\n"; + #sleep .2; + #open(LED, "/opt/bin/setLEDs 0 1 2|") or die "Cannot set LED $!\n"; + #sleep .2; + #open(LED, "/opt/bin/setLEDs 0 1 2 3|") or die "Cannot set LED $!\n"; + #sleep .2; + #open(LED, "/opt/bin/setLEDs 0 1 2 3 4|") or die "Cannot set LED $!\n"; + #sleep .2; + #open(LED, "/opt/bin/setLEDs 0 1 2 3 4 5|") or die "Cannot set LED $!\n"; + #sleep .2; + close(LOG); + exit 0; + } + } + + print LOG "\tNo valid networks\n"; + #open(LED, "/opt/bin/setLEDs 0 1 2 3 4 5 6 7 |") or die "Cannot set LED $!\n"; + #sleep 1; + #open(LED, "/opt/bin/setLEDs |") or die "Cannot set LED $!\n"; + #sleep 1; + #open(LED, "/opt/bin/setLEDs 0 1 2 3 4 5 6 7 |") or die "Cannot set LED $!\n"; + #sleep 1; + #open(LED, "/opt/bin/setLEDs |") or die "Cannot set LED $!\n"; + + close(LOG); + exit 0; Index: tryGateways.pl =================================================================== RCS file: /cvsroot/terk/embed/src/scripts/tryGateways.pl,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** tryGateways.pl 6 Jun 2006 18:31:26 -0000 1.5 --- tryGateways.pl 13 Jun 2006 20:44:06 -0000 1.6 *************** *** 1,6 **** #!/opt/bin/microperl ! #$RELAY_IP = "128.2.211.159"; ! $RELAY_IP = "lion-o.terk.ri.cmu.edu"; open (ROUTES, "/bin/netstat -nr |") or die "Cannot netstat $!\n"; --- 1,13 ---- #!/opt/bin/microperl ! $file = '/opt/connectlog0.txt'; # Log file ! open(LOG, ">>$file"); # Open for appending ! ! ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); ! ! printf LOG "%02d:%02d:%02d ", $hour, $min, $sec; ! print LOG "tryGateways.pl\n"; ! ! $RELAY_IP = "128.2.211.159"; open (ROUTES, "/bin/netstat -nr |") or die "Cannot netstat $!\n"; *************** *** 10,14 **** ($Destination, $Gateway, $Genmask, $Flags, $MSS, $Window, $irtt, $Iface) = split(); if($Flags =~ m/UG/){ ! print "$Gateway is a gateway on $Iface\n"; $Gateways{$Iface} = $Gateway; $Interfaces{$Iface} = $Iface; --- 17,21 ---- ($Destination, $Gateway, $Genmask, $Flags, $MSS, $Window, $irtt, $Iface) = split(); if($Flags =~ m/UG/){ ! print LOG "\t$Gateway is a gateway on $Iface\n"; $Gateways{$Iface} = $Gateway; $Interfaces{$Iface} = $Iface; *************** *** 23,68 **** if($i > 1){ ! print "We have more than 1 default gateway.. in fact we have $i, and this may be a problem\n"; ($successes, $max_delay) = ping($RELAY_IP, 4); ! print "ping responded $successes times with a maximum delay of $max_delay\n"; if($successes > 0){ ! print "We had some successes pinging, yeah! Exiting\n"; $Interface = each(%Gateways); $CurrentInterface = $Interfaces{$Interface}; ! open(SETHOSTNAME, "/opt/scripts/setHostname.pl $CurrentInterface |") or die "Failed to set hostname $!\n"; while(<SETHOSTNAME>){ ! print $_; } exit 0; } else { ! print "We cannot ping our relay, turning off the routes\n"; while($Interface = each(%Gateways)){ $Gateway = $Gateways{$Interface}; ! open(DELROUTE, "/sbin/route del default gw $Gateway |") or die "Failed to delete route $!\n"; ! print "/sbin/route del default gw $Gateway\n"; } ! print "Turning on one route at a time\n"; while($Interface = each(%Gateways)){ $Gateway = $Gateways{$Interface}; open(ADDROUTE, "/sbin/route add default gw $Gateway |"); ! print "/sbin/route add default gw $Gateway\n"; ($individual_success, $dummy) = ping($RELAY_IP, 4); if($individual_success > 0){ $CurrentInterface = $Interfaces{$Interface}; ! print "successfully pinged with gateway $Gateway, setting hostname from $CurrentInterface then exiting\n"; open(SETHOSTNAME, "/opt/scripts/setHostname.pl $CurrentInterface |"); while(<SETHOSTNAME>){ ! print $_; } ! open(LED, "/opt/bin/setLEDs 0 |") or die "Cannot set LED $!\n"; ! sleep .2; ! open(LED, "/opt/bin/setLEDs 0 1|") or die "Cannot set LED $!\n"; ! ! exit 0; } else { ! print "failed to ping on $Gateway\n"; open(DELROUTE, "/sbin/route del default gw $Gateway |"); } --- 30,74 ---- if($i > 1){ ! print LOG "\tWe have more than 1 default gateway.. in fact we have $i, and this may be a problem\n"; ($successes, $max_delay) = ping($RELAY_IP, 4); ! print LOG "\tping responded $successes times with a maximum delay of $max_delay\n"; if($successes > 0){ ! print LOG "\tWe had some successes pinging, yeah! Exiting\n"; $Interface = each(%Gateways); $CurrentInterface = $Interfaces{$Interface}; ! open(SETHOSTNAME, "/opt/scripts/setHostname.pl $CurrentInterface |"); while(<SETHOSTNAME>){ ! print LOG $_; } + close(LOG); exit 0; } else { ! print LOG "\tWe cannot ping our relay, turning off the routes\n"; while($Interface = each(%Gateways)){ $Gateway = $Gateways{$Interface}; ! open(DELROUTE, "/sbin/route del default gw $Gateway |"); ! print LOG "\t/sbin/route del default gw $Gateway\n"; } ! print LOG "\tTurning on one route at a time\n"; while($Interface = each(%Gateways)){ $Gateway = $Gateways{$Interface}; open(ADDROUTE, "/sbin/route add default gw $Gateway |"); ! print LOG "\t/sbin/route add default gw $Gateway\n"; ($individual_success, $dummy) = ping($RELAY_IP, 4); if($individual_success > 0){ $CurrentInterface = $Interfaces{$Interface}; ! print LOG "\tsuccessfully pinged with gateway $Gateway, setting hostname from $CurrentInterface then exiting\n"; open(SETHOSTNAME, "/opt/scripts/setHostname.pl $CurrentInterface |"); while(<SETHOSTNAME>){ ! print LOG $_; } ! # open(LED, "/opt/bin/setLEDs 0 1 2 3 4 5 6 7|") or die "Cannot set LED $!\n"; ! close(LOG); ! exit 0; } else { ! print LOG "\tfailed to ping on $Gateway\n"; open(DELROUTE, "/sbin/route del default gw $Gateway |"); } *************** *** 73,104 **** $CurrentInterface = $Interfaces{$Interface}; ! print "We have one default gateway, it's on $CurrentInterface, setting hostname from it.\n"; open(SETHOSTNAME, "/opt/scripts/setHostname.pl $CurrentInterface |"); while(<SETHOSTNAME>){ ! print $_; } ! open(LED, "/opt/bin/setLEDs 0 1 |") or die "Cannot set LED $!\n"; exit 0; } ! print "No gateways worked.\n"; ! ! open(LED, "/opt/bin/setLEDs 0 1 7|") or die "Cannot set LED $!\n"; #One ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 7|") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 1 |") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 |") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 1 7|") or die "Cannot set LED $!\n"; #Two ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 7|") or die "Cannot set LED $!\n"; ! sleep 1; ! open(LED, "/opt/bin/setLEDs 0 |") or die "Cannot set LED $!\n"; ! sleep 1; ! ! open(RECONNECT, "/opt/scripts/reconnect.sh |") or die "Cannot run reconnect.sh $!\n"; ! exit 0; sub ping{ --- 79,94 ---- $CurrentInterface = $Interfaces{$Interface}; ! print LOG "\tWe have one default gateway, it's on $CurrentInterface, setting hostname from it.\n"; open(SETHOSTNAME, "/opt/scripts/setHostname.pl $CurrentInterface |"); while(<SETHOSTNAME>){ ! print LOG $_; } ! # open(LED, "/opt/bin/setLEDs 0 1 2 3 4 5 6 7|") or die "Cannot set LED $!\n"; ! close(LOG); exit 0; } ! print LOG "\tNo gateways worked.\n"; ! #open(LED, "/opt/bin/setLEDs|") or die "Cannot set LED $!\n"; sub ping{ *************** *** 109,113 **** while (<PING>) { ! # print "$_"; if (/^(\d+) packets transmitted, (\d+) /) { $pkts_sent = $1; --- 99,103 ---- while (<PING>) { ! # print LOG "$_"; if (/^(\d+) packets transmitted, (\d+) /) { $pkts_sent = $1; Index: getIP.pl =================================================================== RCS file: /cvsroot/terk/embed/src/scripts/getIP.pl,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** getIP.pl 2 May 2006 18:43:09 -0000 1.3 --- getIP.pl 13 Jun 2006 20:44:06 -0000 1.4 *************** *** 1,4 **** --- 1,11 ---- #!/opt/bin/microperl + $file = '/opt/connectlog0.txt'; # Log file + open(LOG, ">>$file"); # Open for appending + + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); + + printf LOG "%02d:%02d:%02d ", $hour, $min, $sec; + print LOG "getIP.pl\n"; sub ifconfig2list() *************** *** 150,158 **** my($interfaceName) = shift; my(%interface) = %{$allInterfaces{$interfaceName}}; ! print "\n $interfaceName \n"; my($key,$value); ! print "\n\n[$interfaceName]======================================\n"; foreach $key (sort(keys(%interface))){ ! print "$key=" . $interface{$key} . "\n"; } } --- 157,165 ---- my($interfaceName) = shift; my(%interface) = %{$allInterfaces{$interfaceName}}; ! print LOG "\n\t $interfaceName \n"; my($key,$value); ! print LOG "\n\n\t[$interfaceName]======================================\n"; foreach $key (sort(keys(%interface))){ ! print LOG "\t$key=" . $interface{$key} . "\n"; } } *************** *** 177,181 **** if(@ARGV != 1){ ! print "Usage is getIP <adapter>\n"; exit; } --- 184,189 ---- if(@ARGV != 1){ ! print LOG "\tUsage is getIP <adapter>\n"; ! close(LOG); exit; } *************** *** 184,188 **** my(%interfaces) = parseIfconfig(@lines); ! print getKey(%interfaces, $ARGV[0], "a_inet") . "\n"; #print $1; --- 192,197 ---- my(%interfaces) = parseIfconfig(@lines); ! print LOG "\t"; ! print LOG getKey(%interfaces, $ARGV[0], "a_inet") . "\n"; #print $1; |