This commit is contained in:
Christoph 2023-12-08 10:59:51 +01:00
commit 3b719c200e

77
speedtest.sh Executable file
View File

@ -0,0 +1,77 @@
#!/usr/bin/env bash
script_name="$(basename $(realpath $0))"
working_dir="$(dirname $(realpath $0))"
LOCK_DIR="/tmp/${script_name%%.*}.LOCK"
log_file="${LOCK_DIR}/${script_name%%.*}.log"
error_log="${LOCK_DIR}/${script_name%%.*}.err"
# ----------
# Base Function(s)
# ----------
clean_up() {
# Perform program exit housekeeping
rm -rf "$LOCK_DIR"
blank_line
exit $1
}
blank_line() {
if $terminal ; then
echo ""
fi
}
# ----------
# Check some prerequisites
# ----------
if [[ -t 1 ]] ; then
terminal=true
else
terminal=false
fi
# ----------
# - Jobhandling
# ----------
# - If job already runs, stop execution..
# -
if mkdir "$LOCK_DIR" 2> /dev/null ; then
## - Remove lockdir when the script finishes, or when it receives a signal
trap "clean_up 1" SIGHUP SIGINT SIGTERM
else
datum=`date +"%d.%m.%Y"`
msg="[ Error ]: A previos instance of \"`basename $0`\" seems already be running.\n\tExiting now.."
echo ""
echo "[ Error ]: A previos instance of that script \"`basename $0`\" seems already be running."
echo ""
echo -e " Exiting now.."
echo ""
exit 1
fi
speedtest_log=/var/log/speedtest-cli.log
speedtest-cli --simple > $log_file 2> $error_log
if [[ $? -eq 0 ]]; then
echo -e "\n\n[ $(date +"%Y-%m-%d %H:%M Uhr") ]\n" >> ${speedtest_log}
cat "$log_file" >> ${speedtest_log}
fi
clean_up 0