shellcheck manual fixes (#4)

This commit is contained in:
n 2023-10-19 17:53:44 +02:00
parent 13e8b15ba3
commit 07c0c7a04d
Signed by: n
GPG Key ID: 510227DD6C502CE3
4 changed files with 19 additions and 15 deletions

View File

@ -9,7 +9,7 @@ then
return 0 return 0
fi fi
errorOutput=$(echo "gemini://$1/" | ${TLS_CLIENT} $1 2>&1 > /dev/null) errorOutput=$(echo "gemini://$1/" | ${TLS_CLIENT} "$1" 2>&1 > /dev/null)
errorCode=$? errorCode=$?
if [ $errorCode -gt 0 ] if [ $errorCode -gt 0 ]

View File

@ -25,6 +25,9 @@ while getopts "hF:C:W:" opt; do
F) F)
file=$OPTARG file=$OPTARG
;; ;;
*)
echo "Usage: $0 [-h] [-w <warning> (default: $warning)] [-c <critical> (default: $critical) -F <filename>]"
exit 3
esac esac
done done
@ -32,13 +35,13 @@ shift $((OPTIND-1))
[ "$1" = "--" ] && shift [ "$1" = "--" ] && shift
if [ -z ${file} ] if [ -z "${file}" ]
then then
echo "ERROR: please provide filename to parse with $0 -F <filename>" echo "ERROR: please provide filename to parse with $0 -F <filename>"
exit 3 exit 3
fi fi
lastdate=$(tail -2 ${file} | grep -o -E '^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}') lastdate=$(tail -2 "${file}" | grep -o -E '^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}')
lastts=$(date -d "${lastdate}" +%s) lastts=$(date -d "${lastdate}" +%s)
currentts=$(date +%s) currentts=$(date +%s)
@ -50,13 +53,13 @@ else
exit 3 exit 3
fi fi
message=$(echo "${file} not updated since ${delay} seconds") message="${file} not updated since ${delay} seconds"
if [ ${delay} -gt ${critical} ] if [ "${delay}" -gt "${critical}" ]
then then
echo "CRITICAL: ${message}" echo "CRITICAL: ${message}"
exit 2 exit 2
elif [ ${delay} -gt ${warning} ] elif [ "${delay}" -gt "${warning}" ]
then then
echo "WARNING: ${message}" echo "WARNING: ${message}"
exit 1 exit 1

View File

@ -1,4 +1,5 @@
#!/bin/sh #!/bin/sh
# check postgresql (streaming) replication # check postgresql (streaming) replication
# tested with postgresql 11.3 on FreeBSD 11.2 # tested with postgresql 11.3 on FreeBSD 11.2
# #
@ -6,15 +7,15 @@
# warning (-w) and critical (-c) thresholds can be set in seconds # warning (-w) and critical (-c) thresholds can be set in seconds
# on a low trafic server don't hesitate to set them to a high value # on a low trafic server don't hesitate to set them to a high value
args=`getopt hw:c: $*` args=$(getopt hw:c: "$*")
set -- $args set -- "$args"
warning=600 warning=600
critical=3600 critical=3600
while :; do while :; do
case "$1" in case "$1" in
-h) echo "Usage: $0 [-h] [-w <warning> (default: $warning)] [-c <critical> (default: $critical)]" -h) echo "Usage $0: [-h] [-w warning (default: $warning)] [-c critical (default: $critical)]"
shift; shift;
exit 2; exit 2;
;; ;;
@ -30,13 +31,13 @@ while :; do
esac esac
done done
delay=`/usr/local/bin/psql -U postgres --pset expanded=yes -c "select now() - pg_last_xact_replay_timestamp() AS replication_delay;" | tail -2 | head -1 | cut -d '|' -f 2 | cut -d ' ' -f 2 | cut -d '.' -f 1 | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }'` delay=$(/usr/local/bin/psql --port=6432 --username=postgres --pset="expanded=yes" --command="select now() - pg_last_xact_replay_timestamp() AS replication_delay;" | tail -2 | head -1 | cut -d '|' -f 2 | cut -d ' ' -f 2 | cut -d '.' -f 1 | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')
if [ $delay -gt $critical ] if [ "$delay" -gt "$critical" ]
then then
echo "CRITICAL: $delay seconds behind master" echo "CRITICAL: $delay seconds behind master"
exit 2 exit 2
elif [ $delay -gt $warning ] elif [ "$delay" -gt "$warning" ]
then then
echo "WARNING: $delay seconds behind master" echo "WARNING: $delay seconds behind master"
exit 1 exit 1

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
HOSTNAME="${COLLECTD_HOSTNAME:-`hostname -f`}" HOSTNAME="${COLLECTD_HOSTNAME:-$(hostname -f)}"
INTERVAL="${COLLECTD_INTERVAL:-300}" INTERVAL="${COLLECTD_INTERVAL:-300}"
FILE="/home/weather/tmp/openweathermap.json" FILE="/home/weather/tmp/openweathermap.json"
@ -9,8 +9,8 @@ FILE="/home/weather/tmp/openweathermap.json"
while sleep "$INTERVAL"; do while sleep "$INTERVAL"; do
for field in main.temp main.feels_like main.pressure main.humidity wind.speed wind.gust clouds.all rain.\"1h\" rain.\"3h\" snow.\"1h\" snow.\"3h\" sys.sunrise sys.sunset visibility;do for field in main.temp main.feels_like main.pressure main.humidity wind.speed wind.gust clouds.all rain.\"1h\" rain.\"3h\" snow.\"1h\" snow.\"3h\" sys.sunrise sys.sunset visibility;do
key=`echo ${field} | sed 's/\./-/g' | sed 's/"//g'` key=$(echo "$field" | sed 's/\./-/g' | sed 's/"//g')
echo "PUTVAL $HOSTNAME/weather/gauge-${key} interval=$INTERVAL N:`jq .${field} $FILE | sed s/null/0/g`" ; echo "PUTVAL $HOSTNAME/weather/gauge-${key} interval=$INTERVAL N:$(jq ."$field" $FILE | sed s/null/0/g)" ;
done done
done done