Skip to content

Instantly share code, notes, and snippets.

@jeromatron
Created December 30, 2014 23:04
Show Gist options
  • Save jeromatron/ef1826e3ec99e96c6bf1 to your computer and use it in GitHub Desktop.
Save jeromatron/ef1826e3ec99e96c6bf1 to your computer and use it in GitHub Desktop.
#!/bin/sh
# A shell script you can give to customers to check if all their repair sessions are complete.
# Change SYSTEM_LOG_PATH to the directory containing system.log
if [ "x$SYSTEM_LOG_PATH" = "x" ]; then
SYSTEM_LOG_PATH=.
fi
LOG_FILE_PATTERN=*.log*
NEW_SESSION_PATH=/tmp/new-session
COMPLETED_SESSION_PATH=/tmp/completed-successfully
echo Parsing the SYSTEM_LOG_PATH: $SYSTEM_LOG_PATH
grep 'new session' $SYSTEM_LOG_PATH/$LOG_FILE_PATTERN | cut -d# -f2 | cut -d] -f1 | sort | uniq > $NEW_SESSION_PATH
grep 'completed successfully' $SYSTEM_LOG_PATH/$LOG_FILE_PATTERN | cut -d# -f2 | cut -d] -f1 | sort | uniq > $COMPLETED_SESSION_PATH
INCOMPLETE_SESSIONS=$(grep -vf $COMPLETED_SESSION_PATH $NEW_SESSION_PATH)
NEW_SESSION_COUNT=$(wc -l $NEW_SESSION_PATH | awk {'print $1'})
COMPLETED_SESSION_COUNT=$(wc -l $COMPLETED_SESSION_PATH | awk {'print $1'})
echo New session count: $NEW_SESSION_COUNT
echo Completed session count: $COMPLETED_SESSION_COUNT
if [ $NEW_SESSION_COUNT -eq 0 ] && [ $COMPLETED_SESSION_COUNT -eq 0 ]; then
echo "Warning: new and completed session counts were 0"
fi
rm $COMPLETED_SESSION_PATH $NEW_SESSION_PATH
if [ -z $INCOMPLETE_SESSIONS ]; then
echo All sessions complete.
exit 0
else
echo The following sessions are not complete:
echo $INCOMPLETE_SESSIONS
exit 255
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment