From 6903476f02ba382916272bce8fcb2d369dec68aa Mon Sep 17 00:00:00 2001 From: AE6XE Date: Fri, 11 Dec 2015 10:25:38 -0800 Subject: [PATCH] feature: snrlog updates to handle host name change and lack of hostname or ip info --- files/usr/local/bin/snrlog | 56 +++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/files/usr/local/bin/snrlog b/files/usr/local/bin/snrlog index e1912b94..0ff31e3a 100755 --- a/files/usr/local/bin/snrlog +++ b/files/usr/local/bin/snrlog @@ -40,24 +40,66 @@ $sigdir="/sys/kernel/debug/ieee80211/phy0/netdev\:wlan0/stations"; $nf = `iw wlan0 survey dump | grep -A 1 'in use' | tail -1`; $nf =~ s/^[^-\d]*([-\d]+).*$/$1/; chomp $nf; + if (! -e $tmpdir ) { system("mkdir $tmpdir > /dev/null"); } ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); $d = sprintf ("%02d/%02d %02d:%02d:%02d",$mon+1, $mday,$hour, $min, $sec); -foreach $sigmac ( `ls $sigdir` ) +foreach $sigmac ( `ls $sigdir` ) { chomp $sigmac; + $filename = `ls $tmpdir/$sigmac*` ; + $filename =~ /^.*\/([^-]*)-(.*)$/; + $isFile = $1; + $hnamef = $2; + chomp ($ip = `cat /proc/net/arp | grep $sigmac | cut -f1 -d\" "`); $hname=""; - foreach(`nslookup $ip`) - { - next unless ($hname) = /Address 1: $ip (\S+)/; + foreach(`nslookup $ip`) + { + next unless ($hname) = /Address 1: $ip (\S+)/; $hname =~ s/\..*$// ; break; - } - - $sigdat = "$sigmac-$hname"; + } + + if (($hnamef and $hnamef eq $hname ) or ($hname and ! $isFile )) + { + $sigdat = "$sigmac-$hname"; + } + elsif ( $hnamef eq $ip and $hname ) + { + system("mv $tmpdir/$sigmac-$ip $tmpdir/$sigmac-$hname > /dev/null"); + $sigdat = "$sigmac-$hname"; + } + elsif ($hname and ! $hnamef and $isFile ) + { + system("mv $tmpdir/$sigmac- $tmpdir/$sigmac-$hname > /dev/null"); + $sigdat = "$sigmac-$hname"; + } + elsif (( $hnamef eq $ip) or ( $ip and ! $isFile )) + { + $sigdat = "$sigmac-$ip"; + } + elsif ( $isFile and ! $hnamef and $ip ) + { + system("mv $tmpdir/$sigmac- $tmpdir/$sigmac-$ip > /dev/null"); + $sigdat = "$sigmac-$ip"; + } + elsif ($hnamef and ! $hname ) + { + $sigdat = "$sigmac-$hnamef"; + } + elsif ( $hnamef and $hname and $hnamef ne $hname ) + { + system("mv $tmpdir/$sigmac-$hnamef $tmpdir/$sigmac-$hname > /dev/null"); + $sigdat = "$sigmac-$hname"; + } + else + { + $sigdat = "$sigmac-"; + } + chomp ($siglevel = `cat $sigdir/$sigmac/last_signal`) ; if ($siglevel < -100 or $siglevel >= 0 ) { next; }