More scripts from tools dir.

This commit is contained in:
Ben Greear
2017-10-06 13:55:23 -07:00
parent 72712ff548
commit 4e92bab89b
7 changed files with 365 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
# test of the attenuator loop
channels, 1.1.14.1, 1.1.14.2, 1.1.14.3, 1.1.3.1, 1.1.3.2, 1.1.3.3
delay,1000
950,850,750, 950,850,750
sleep,1000
-10,-10,-10, -10,-10,-10
-10,-10,NA, -10,-10,NA
-10,-10,NA, -10,-10,NA
-10,-10,-10, -10,-10,-10
+10,+10,+10, +10,+10,+10
+10,+10,NA, +10,+10,NA
+10,+10,NA, +10,+10,NA
+10,+10,+10, +10,+10,+10
# eof
1 # test of the attenuator loop
2 channels, 1.1.14.1, 1.1.14.2, 1.1.14.3, 1.1.3.1, 1.1.3.2, 1.1.3.3
3 delay,1000
4 950,850,750, 950,850,750
5 sleep,1000
6 -10,-10,-10, -10,-10,-10
7 -10,-10,NA, -10,-10,NA
8 -10,-10,NA, -10,-10,NA
9 -10,-10,-10, -10,-10,-10
10 +10,+10,+10, +10,+10,+10
11 +10,+10,NA, +10,+10,NA
12 +10,+10,NA, +10,+10,NA
13 +10,+10,+10, +10,+10,+10
14 # eof

36
lcheck.sh Executable file
View File

@@ -0,0 +1,36 @@
#!/bin/bash
#set -x
set -e
if [ -z "$1" ]; then
lic_file="/home/lanforge/license.txt"
else
lic_file="$1"
fi
if [ ! -f "$lic_file" ]; then
echo "File not found [$lic_file]"
exit 1
fi
declare -a lic_lines
IFS=$'\n' lic_lines=(`cat $lic_file`)
if [[ ${#lic_lines[@]} -lt 2 ]]; then
echo "Nothing found in [$lic_file]"
exit 1
fi
NOW=`date +%s`
num_expired=0
for line in "${lic_lines[@]}"; do
[[ "$line" = "" ]] && continue;
IFS=$' ' hunks=($line)
lastbit=${hunks[4]}
[[ "$lastbit" = "" ]] && echo "Unable to determine timecode for ${hunks[0]}" && continue
delta=$(( $lastbit - $NOW ))
if [[ $delta -lt 86200 ]] && [[ $delta -gt 0 ]] ; then
echo "${hunks[0]} expires today!"
elif [[ $delta -le 0 ]]; then
echo "${hunks[0]} expired"
((num_expired++)) || true
fi
done
exit $num_expired
#

31
print_udev.sh Executable file
View File

@@ -0,0 +1,31 @@
#!/bin/bash
li_show_lines=$(ip -o li show)
while read line ; do
#echo "* $line"
line=${line#*: }
ifname=''
mac=''
case $line in
eth* | enp* | wlan*)
#echo "LIKE: $line"
hunks=($line);
ifname="${hunks[0]}"
ifname="${ifname%:*}"
#echo "N: ${#hunks[@]}"
for i in `seq 1 ${#hunks[@]}`; do
#echo "$i ${hunks[$i]}"
if [ ! -z "${hunks[$i]}" -a "${hunks[$i]}" = "link/ether" ]; then
mac="${hunks[ $[ $i + 1] ]}"
break;
fi
done
#echo "Hi! $ifname has [$mac]"
echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="'$mac'", ATTR{dev_id}=="0x0", ATTR{type}=="1", NAME="'$ifname'"'
;;
*)
#echo "IGNORING: $line"
;;
esac
done <<< "$li_show_lines"

49
sensorz.pl Executable file
View File

@@ -0,0 +1,49 @@
#!/usr/bin/perl -w
use strict;
use warnings;
use diagnostics;
my @sensor_lines = `sensors`;
my @sensor_devices = [];
my %sensor_readings = ();
my $temp = 0;
my $device = "Unknown";
for my $line (@sensor_lines) {
next if ($line =~ /^\s*$/);
chomp $line;
if ($line =~ /^[^: ]+$/) {
($::device) = $line =~ /^(.*?-\d+)$/;
next if ($line !~ /^(ath10k_hwmon-pci|physical|coretemp|Core )/);
if ( !defined $::sensor_readings{$::device}) {
$::sensor_readings{$::device} = 0;
push(@::sensor_devices, $::device);
}
next;
}
next if ($line !~ /^(temp|physical|coretemp)/i);
my $t = 0;
if ($line =~ m{.*?:\s+N/A}) {
$t = 0;
}
else {
($t) = $line =~ /.*?:\s+[+](\d+(\.\d+)?)°C/;
}
$::temp = $t if (!defined $::temp || $t > $::temp);
$::sensor_readings{ $::device } = $::temp;
#print "Device[$::device] temp[$::temp]\n";
#$::device = "Unknown";
$::temp = 0;
}
for my $dev (@::sensor_devices) {
print "$dev, ";
}
print "\n";
for my $dev (@::sensor_devices) {
print "$::sensor_readings{$dev}, ";
}
print "\n";

80
sysmon.sh Executable file
View File

@@ -0,0 +1,80 @@
#!/bin/bash
# grabs netdev stats and timestamp every second or so, saves
# to logfile.
# Usage:
#
# Monitor every 60 seconds
# ./sysmon.sh 60
#
# Monitor every 5 seconds (default)
# ./sysmon.sh
USAGE="Usage: sysmon.sh [ -s sleep_time ] [ -p ] [ -h ]\n
-p means show port stats\n
-s specifies sleep-time between reports.\n
-h Show help and exit.\n
"
log="/home/lanforge/sysmon.log"
sleep_time=5
show_port_stats=0
while getopts "s:hp" opt; do
case "$opt" in
s)
sleep_time=${OPTARG}
;;
h)
echo -e $USAGE
exit 0
;;
p)
show_port_stats=1
;;
*)
echo -e $USAGE
exit 1
;;
esac
done
# Reset arguments to $1, $2, etc.
shift $((OPTIND - 1))
echo "Starting sysmon.sh script, sleep-time: $sleep_time."
if [ $show_port_stats == "1" ]
then
echo "Gathering interface stats."
else
echo "NOT gathering interface stats."
fi
echo "Starting sysmon.sh script." > $log;
while true
do
echo "Logging system stats to $log..."
date
date +"%Y-%m-%d %H:%M:%S" >> $log
# netdev link stats.
if [ $show_port_stats == "1" ]
then
echo "Link stats:" >> $log
ip -s link show >> $log
fi
date +"%Y-%m-%d %H:%M:%S" >> $log
echo "Process Listing: " >> $log
COLUMNS=512 LINES=15000 top -b -n 1 -w512 -c >> $log 2>/dev/null
echo "Memory Info: " >> $log
cat /proc/meminfo >> $log
echo "Disk-Free Info: " >> $log
df >> $log
# Show free-memory on console. Can direct to /dev/null if
# user does not want to see this.
grep MemFree /proc/meminfo
date +"%Y-%m-%d %H:%M:%S" >> $log
echo "" >> $log
sleep $sleep_time
done

123
test_refcnt.pl Executable file
View File

@@ -0,0 +1,123 @@
#!/usr/bin/perl
# Un-buffer output
$| = 1;
use strict;
my $sleep_time = 30;
my $vlans = 100;
my $ip_base = "192.168.10";
my $gw = "192.168.10.1";
my $lsb_start = 10;
my $eth_dev = "eth0";
my $vid_base = 1000;
my $i;
my $vid;
my @pids = ();
my $peer = 0;
if ($ARGV[0] eq "p") {
# when running on peer machine...
print "Running in peer mode..\n";
$peer = 1;
$lsb_start += $vlans;
$gw = "192.168.10.250";
}
#`rmmod 8021q`;
#`modprobe 8021q`;
my $loop = 0;
while (1) {
print "Creating and configuring vlans..loop: $loop\n";
for ($i = 0; $i<$vlans; $i++) {
$vid = $vid_base + $i;
my $v = "$eth_dev.$vid";
my $lsb = $lsb_start + $i;
#print "Creating & configuring VLAN: $eth_dev.$vid\n";
`vconfig add $eth_dev $vid`;
#my $cmd = "ifconfig $v $ip_base.$lsb netmask 255.255.255.0 up";
#print "Configuring with command -:$cmd:-\n";
#`$cmd`;
my $tbl = $i + 1;
printAndExec("ip link set $v down");
printAndExec("ip link set $v up");
printAndExec("ip addr flush dev $v > /dev/null 2>&1");
printAndExec("ip address add $ip_base.$lsb/24 broadcast $ip_base.255 dev $v");
printAndExec("ip link set dev $v up");
printAndExec("ip ru add from $ip_base.$lsb/32 table $tbl");
printAndExec("ip route add $ip_base.0/24 via $ip_base.$lsb table $tbl");
printAndExec("ip route add 0/0 via $gw dev $v table $tbl");
printAndExec("echo 1 > /proc/sys/net/ipv4/conf/$v/arp_filter");
# Start traffic on interface
my $kidpid;
if (!defined($kidpid = fork())) {
# fork returned undef, so failed
die "Cannot fork: $!";
} elsif ($kidpid == 0) {
# fork returned 0, so this branch is child
while (1) {
my $url;
if ($peer) {
my $mip = $lsb - $vlans;
$url = "http://$ip_base.$mip/index.html";
}
else {
my $mip = $lsb + $vlans;
$url = "http://$ip_base.$mip/index.html";
#print "url: $url\n";
}
my $curl_cmd = "curl --interface $eth_dev.$vid --url $url -o $eth_dev.$vid.index.html > /dev/null 2>&1";
#print "Child process running: $curl_cmd\n";
system("$curl_cmd");
sleep(5);
}
} else {
# fork returned 0 nor undef
# so this branch is parent
@pids = (@pids, $kidpid);
# waitpid($kidpid, 0);
}
}
my $slp = (rand() * 1000000) % $sleep_time;
if ($slp < 3) {
$slp = 3;
}
print " Done creating vlans and starting curl processes, sleeping $slp seconds.\n";
# Sleep a while to wait for curl to do it's thing
sleep($slp);
print " Removing all VLANs.\n";
for ($i = 0; $i<$vlans; $i++) {
$vid = $vid_base + $i;
#print "Removing vlan: $eth_dev.$vid\n";
`vconfig rem $eth_dev.$vid`;
}#for
print " Killing all curl instances.\n";
for ($i = 0; $i<@pids; $i++) {
`kill -9 $pids[$i]`;
}
print " Done with loop: $loop\n";
$loop++;
}# while
sub printAndExec {
my $cmd = $_[0];
#print "$cmd\n";
# NOTE: If you use the single back-ticks here, it will hang, probably some
# signal problem...never figured out why really (ERESTARTSYS) was the error
# that perl hung on... --Ben
system("$cmd");
}

31
topmon.sh Executable file
View File

@@ -0,0 +1,31 @@
#!/bin/bash
## ##
## Top and Memory Usage Reporter ##
## ##
## Use this script to regularly record the ##
## free memory and number of processes running ##
## on your LANforge server. ##
## ##
## This script can be installed into cron by ##
## one of two methods: ##
## a) ln -s `pwd`/topmon.sh /etc/cron.hourly ##
## ##
## Or more frequently: ##
## b) crontab -u lanforge -e ##
## and add the line ##
## * */3 * * * /home/lanforge/scripts/topmon </dev/null &>/dev/null ##
## ##
## Find the results in /home/lanforge/topmon.log ##
## ##
max_size="100MB"
log="/home/lanforge/topmon.log"
tmp="/home/lanforge/tmp.topmon.log"
now=$( date +"%Y-%m-%d %H:%M:%S")
echo "" >> $tmp
echo "$now" >> $tmp
echo "" >> $tmp
COLUMNS=512 LINES=15000 top -b -n 1 -w512 -c >> $tmp
echo "" >> $tmp
# save the last 1M of the log file
tail -c $max_size $tmp > $log
#eof