From: Andrew Lorimer Date: Sun, 8 Nov 2020 12:04:57 +0000 (+1100) Subject: add vicroads checker X-Git-Url: https://git.lorimer.id.au/scripts.git/diff_plain/cb52770f9e09125a1187fe8162c6cecc13a5151a?hp=--cc add vicroads checker --- cb52770f9e09125a1187fe8162c6cecc13a5151a diff --git a/nameget.sh b/nameget.sh index bb3d2a1..063544c 100755 --- a/nameget.sh +++ b/nameget.sh @@ -39,6 +39,10 @@ Get a list of urls and optional corresponding output paths, then send them to wg -d, --destination \e[4m\e[0m Directory in which to save each file in LIST Default: ./ + + -n, --number + Maximum number of files to download + Default: none -a, --args \e[4m\e[0m String of shell arguments which are passed verbatim to wget\n" @@ -79,6 +83,15 @@ while [ $# -gt 0 ]; do fi shift ;; + -n|--number) + maxdl=(${2-}) + if [ -z "$maxdl" ] || [ "$maxdl" = " " ]; then + printf "\x1b[31mOption $1 requires an argument\x1b[0m\n\n" + printf "$usageshort" + exit 1 + fi + shift + ;; -a|--args) otherargs=" ${2-}" if [ -z "$otherargs" ] || [ "$otherargs" = " " ]; then @@ -125,15 +138,20 @@ if [[ ! $outdir =~ /$ ]]; then # check if [DESTINATION] has a trailing / output "Starting downloading files in $(readlink -f $list) to $outdir" "\n\e[1m" +n=0 + while read -r url filename; do # Ignore if line is commented [[ "$url" =~ ^\s*#.* ]] && continue + # Stop when maxdl is exceeded + [ ! -z ${maxdl} ] && [[ $n -ge $maxdl ]] && break + # parse output filename destarg='' # placeholder for -O argument (output filename) if [ -z "$filename" ] || [ "filename" = "" ]; then - filename="$(echo $url | sed 's/\/\$//; s/.*\///; s/[_ \.]/-/g; s/\(.*\)/\L\1/; s/^the-//; s/-the\(-movie\)\?\(-film\)\?//g; s/^a-//; s/-\(20\|19\)[0-9]\{2\}.*-\(.*\)/.\2/g; s/-[0-9]\{3,4\}p.*-\(.*\)/.\1/g; s/-ii-/-2-/g; s/-iii-/-3-/g; s/-iv-/-4-/g; s/-v-/-5-/g; s/-vi-/-6-/g; s/-vii-/-7-/g; s/-viii-/-8-/g; s/-viiii-/-9-/g; s/-x-/-10-/g;')" + filename="$(echo $url | sed 's/\/\$//; s/.*\///; s/[_ \.]/-/g; s/\%20/-/g; s/\(.*\)/\L\1/; s/^the-//; s/-the\(-movie\)\?\(-film\)\?//g; s/^a-//; s/-(*\(20\|19\)[0-9]\{2\})*.*-\(.*\)/.\2/g; s/-[0-9]\{3,4\}p.*-\(.*\)/.\1/g; s/-ii-/-2-/g; s/-iii-/-3-/g; s/-iv-/-4-/g; s/-v-/-5-/g; s/-vi-/-6-/g; s/-vii-/-7-/g; s/-viii-/-8-/g; s/-viiii-/-9-/g; s/-x-/-10-/g;')" fi destarg=" -O $outdir$filename" prettyname="$filename from $url" @@ -144,6 +162,7 @@ while read -r url filename; do # compile wget command (for debugging purposes) command="wget$nvarg -R "*index.html*" -c -nd -nH --cut-dirs=100 -np -e robots=off -P $outdir$destarg$otherargs $url" + n=$((n+1)) if [ "$test" ]; then output "$command" " " else diff --git a/pwrstatd-lowbatt.sh b/pwrstatd-lowbatt.sh index 4c59cfb..82dd9e3 100755 --- a/pwrstatd-lowbatt.sh +++ b/pwrstatd-lowbatt.sh @@ -3,6 +3,8 @@ # Send warning email and shut down system when UPS battery is low. # Andrew Lorimer, January 2020 +echo "Received low battery signal" | systemd-cat -t `basename "$0"` + recipient="andrew" ctime=`date` @@ -14,5 +16,5 @@ level=`echo $state | grep -oP 'Battery Capacity\.+ \K\d+'`"%" echo -e "Battery level is $level (expected runtime $runtime) as of $ctime. Shutting down system in one minute.\n$state" | mail -a "Importance: High" -a "Content-Type: text/plain; charset=UTF-8" -s "⚠️🔋 Battery level $level on $model" $recipient sleep 60 -echo "Starting system shutdown due to low battery" | systemd-cat -t `basename "$0"` +echo "Starting system shutdown due to low battery ($level)" | systemd-cat -t `basename "$0"` shutdown now diff --git a/vicroads-checker.sh b/vicroads-checker.sh new file mode 100755 index 0000000..fe28a96 --- /dev/null +++ b/vicroads-checker.sh @@ -0,0 +1,11 @@ +#! /bin/bash +# Script to check the Vicroads website and alert me when bookings for +# license testing are open again. + +recipient="andrew@lorimer.id.au" +url="https://www.vicroads.vic.gov.au" +phrase="No new appointments are available at this time" + +if ! curl -l "$url" | grep "$phrase"; then + echo -e "VicRoads appointments may be available" | mail -a "Importance: High" -a "Content-Type: text/plain; charset=UTF-8" -s "VicRoads Booking Check" $recipient +fi