Created
June 13, 2020 04:47
-
-
Save Septem151/43a56c262c8804908f312bde69d21bdc to your computer and use it in GitHub Desktop.
OSRS Ping Monitor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
highping=80 | |
interval=0.5 | |
function print_usage() { | |
cat <<EOF | |
Usage: $0 <WORLD> <HIGH_PING> <INTERVAL> | |
WORLD [REQUIRED] The world to check ping for. | |
HIGH_PING [OPTIONAL - Default: $highping] The value at which a ping >= value gives a warning. | |
INTERVAL [OPTIONAL - Default: $interval] The interval in seconds for ping updates. | |
EOF | |
} | |
function check_for_args() { | |
if [[ $# -ne 3 && $# -ne 2 && $# -ne 1 ]] | |
then | |
print_usage; exit 1 | |
elif [[ ${1} =~ '^[0-9]+$' ]] | |
then | |
echo "Error: World parameter must be a number." >&2; exit 1 | |
elif [[ ${1} -lt 301 || ${1} -gt 536 ]] | |
then | |
echo "Error: World parameter must be between 301 and 535." >&2; exit 1 | |
else | |
world=$(( ${1} - 300 )) | |
if [ $# -ge 2 ] | |
then | |
if ! [[ ${2} =~ ^(0*[1-9][0-9]*(\.[0-9]+)?|0+\.[0-9]*[1-9][0-9]*)$ ]] | |
then | |
echo "Error: High Ping parameter must be a positive integer or float." >&2; exit 1 | |
else | |
highping=${2} | |
fi | |
if [[ $# -eq 3 ]] | |
then | |
if ! [[ ${3} =~ ^(0*[1-9][0-9]*(\.[0-9]+)?|0+\.[0-9]*[1-9][0-9]*)$ ]] | |
then | |
echo "Error: Interval parameter must be a positive integer or float." >&2; exit 1 | |
else | |
interval=${3} | |
fi | |
fi | |
fi | |
fi | |
} | |
function print_pings() { | |
tput cup `tput lines` 0 | |
while true | |
do | |
ping_value=`ping -c 1 "oldschool${world}.runescape.com" \ | |
| awk 'BEGIN {FS="[=]|[ ]"} NR==2 {print $11}'` | |
if (( $(bc <<< "${ping_value} >= ${highping}") )) | |
then | |
printf "\rHigh Ping detected! Ping: ${ping_value}\n" | |
fi | |
ping_print="Current Ping: ${ping_value}" | |
printf "\r${ping_print}" | |
tput cup `tput lines` $(( `tput cols` - 3 )) | |
sleep ${interval} | |
done | |
} | |
check_for_args $@ | |
if [[ $? -eq 0 ]] | |
then | |
print_pings | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment