mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-10-29 09:52:35 +00:00
adds time range, help text, more time syntax flexibility
This commit is contained in:
@@ -1,5 +1,29 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# timed_ice_pause.sh
|
||||||
|
#
|
||||||
|
# use this script to regularly pause traffic on a WANlink by
|
||||||
|
# dropping all packets for a specified amount of time
|
||||||
|
#
|
||||||
|
# -n name of wanlink
|
||||||
|
# -r run for time period
|
||||||
|
# -p pause traffic for time period
|
||||||
|
# -h show help
|
||||||
|
# -S seconds
|
||||||
|
# -M minutes
|
||||||
|
# -H hours
|
||||||
|
# -D days
|
||||||
|
#
|
||||||
|
# Time period should be a valid argument to sleep(1):
|
||||||
|
# 5s 5 seconds
|
||||||
|
# 6m 6 minutes
|
||||||
|
# 7h 7 hours
|
||||||
|
# 8d 8 days
|
||||||
|
#
|
||||||
|
# Time ranges have to be valid input to shuf(1), just integers:
|
||||||
|
# 1-10 => shuf -i 1-10 -n 1
|
||||||
|
#
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
# scripts
|
# scripts
|
||||||
cd /home/lanforge/scripts
|
cd /home/lanforge/scripts
|
||||||
trap do_sigint INT
|
trap do_sigint INT
|
||||||
@@ -29,7 +53,7 @@ function start_cx() {
|
|||||||
|
|
||||||
function pause_wl() {
|
function pause_wl() {
|
||||||
[ -z "$1" ] && echo "No connection name, bye." && exit 1
|
[ -z "$1" ] && echo "No connection name, bye." && exit 1
|
||||||
[ -z "$2" ] && echo "No sleep seconds, bye." && exit 1
|
[ -z "$2" ] && echo "No sleep time, bye." && exit 1
|
||||||
local name=$1
|
local name=$1
|
||||||
local pause_time=$2
|
local pause_time=$2
|
||||||
|
|
||||||
@@ -94,19 +118,42 @@ function pause_wl() {
|
|||||||
echo -n " go "
|
echo -n " go "
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# provide either a number or a pair of numbers joined by a dash to
|
||||||
|
# generate a random value in that range
|
||||||
|
# select_range 1 returns 1
|
||||||
|
# select_range 1-10 returns
|
||||||
|
function select_range() {
|
||||||
|
[ -z "$1" ] && "echo select_range wants a numeric string, bye" && exit 1
|
||||||
|
|
||||||
|
if [[ $1 = *-* ]]; then
|
||||||
|
echo "$(shuf -i $1 -n1)$unit"
|
||||||
|
else
|
||||||
|
echo "$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
show_help=0
|
show_help=0
|
||||||
run_time_sec=0
|
run_time=0
|
||||||
pause_time_sec=0
|
pause_time_sec=0
|
||||||
link_name=''
|
link_name=''
|
||||||
|
unit=s
|
||||||
|
|
||||||
while getopts "h:n:r:p:" arg; do
|
while getopts "h:n:r:p:SMHD" arg; do
|
||||||
#echo "ARG[$arg] OPTARG[$OPTARG]"
|
#echo "ARG[$arg] OPTARG[$OPTARG]"
|
||||||
case $arg in
|
case $arg in
|
||||||
n) link_name=$OPTARG
|
n) link_name=$OPTARG
|
||||||
;;
|
;;
|
||||||
r) run_time_sec=$OPTARG
|
r) run_time=$OPTARG
|
||||||
;;
|
;;
|
||||||
p) pause_time_sec=$OPTARG
|
p) pause_time=$OPTARG
|
||||||
|
;;
|
||||||
|
S) unit=s
|
||||||
|
;;
|
||||||
|
M) unit=m
|
||||||
|
;;
|
||||||
|
H) unit=h
|
||||||
|
;;
|
||||||
|
D) unit=d
|
||||||
;;
|
;;
|
||||||
h) show_help=1
|
h) show_help=1
|
||||||
;;
|
;;
|
||||||
@@ -115,12 +162,20 @@ while getopts "h:n:r:p:" arg; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -z "$link_name" -o $run_time_sec -eq 0 -o $pause_time_sec -eq 0 ]; then
|
if [ -z "$link_name" -o -z "$run_time" -o -z "$pause_time_sec" ]; then
|
||||||
show_help=1
|
show_help=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $show_help -gt 0 ]; then
|
if [ $show_help -gt 0 ]; then
|
||||||
echo "Usage: $0 -n {CX name} -r {run time in seconds} -p {pause time in seconds}"
|
echo "Usage: $0 -n {CX name} -r {run time} -p {pause time}"
|
||||||
|
echo " Use this on lanforge localhost"
|
||||||
|
echo " time units are assumed to be seconds, or arguments to sleep(1)"
|
||||||
|
echo " $0 -n wanlink1 -r 10m -p 1-2s"
|
||||||
|
echo " or time can be set for ranges with these switches: "
|
||||||
|
echo " units: -S seconds, -M minutes, -H hours, -D days"
|
||||||
|
echo " time can be a number or a range eg 1-10"
|
||||||
|
echo " (units cannot be mixed if they are ranges)"
|
||||||
|
echo " $0 -n wanlink1 -r 10-20 -p 1-2 -M"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -128,9 +183,7 @@ fi
|
|||||||
echo "Starting connection $link_name..."
|
echo "Starting connection $link_name..."
|
||||||
start_cx $link_name
|
start_cx $link_name
|
||||||
while true; do
|
while true; do
|
||||||
sleep $run_time_sec
|
sleep $(select_range $run_time)
|
||||||
#echo "pausing..."
|
pause_wl "$link_name" $(select_range $pause_time)
|
||||||
pause_wl $link_name $pause_time_sec
|
|
||||||
#echo "resumed"
|
|
||||||
done
|
done
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user