-d, --destination \e[4m<destination>\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<args>\e[0m
String of shell arguments which are passed verbatim to wget\n"
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
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"
# 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
# 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`
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
--- /dev/null
+#! /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