From 8815b0cabd168319a7fe4bd4799726e9c9399c7e Mon Sep 17 00:00:00 2001 From: Steve Magnuson Date: Thu, 22 Jul 2021 16:05:20 -0700 Subject: [PATCH] Fix date calculation in vnc-server-activity.sh --- vnc-server-activity.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vnc-server-activity.sh b/vnc-server-activity.sh index d9cac3f..d5dce42 100755 --- a/vnc-server-activity.sh +++ b/vnc-server-activity.sh @@ -6,7 +6,7 @@ # Usage: vnc-server-activity.sh [email-address[,email-address]...] # -VERSION="1.2.0" +VERSION="1.2.1" # Pat and patmail.sh must be installed. If they are not, exit. command -v pat >/dev/null 2>&1 || exit 1 @@ -28,13 +28,13 @@ if [[ -s $FILES ]] then echo "VNC Activity" > $OUTFILE grep -h Connections $FILES* 2>/dev/null 1>$FILTERED - if [ -s $FILTERED ] + if [[ -s $FILTERED ]] then while IFS= read -r LINE do D="${LINE%% $HOSTNAME*}" # Extract date from log message E="$(date --date="$D" +'%s')" # Convert date to epoch - if [ $E -gt $NOW ] + if (( $E > $NOW )) then # Now in new year. (Log messages don't include year, so it's a problem going from December to January.) # Account for leap years date -d $(date +%Y)-02-29 >/dev/null 2>&1 && SEC_IN_YEAR=$((60 * 60 * 24 * 366)) || SEC_IN_YEAR=$((60 * 60 * 24 * 365)) @@ -65,8 +65,8 @@ FILES="/usr/share/dwagent/dwagent.log" if [[ -s $FILES ]] then echo -e "\nDWService Activity" >> $OUTFILE - grep -h session $FILES* 2>/dev/null 1>$FILTERED - if [ -s $FILTERED ] + grep -Ihs session $FILES* | grep "^[0-9]*" 2>/dev/null 1>$FILTERED + if [[ -s $FILTERED ]] then while IFS= read -r LINE do