Last active
August 29, 2015 14:12
-
-
Save jeromatron/d73403094cf63621edf5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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'}) | |
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