Last active
December 22, 2015 15:59
-
-
Save momchilov/6496646 to your computer and use it in GitHub Desktop.
This script uses 'logtail' to monitor log activity for selected logfiles and beep the PC speaker when new log messages are discovered.
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/bash | |
# this script beeps the PC speaker when there are new messages available | |
# and shows the new messaegs | |
# | |
# REQUIREMENTS: | |
# | |
# the script requires "logtail" and "beep" to function | |
# it requires kernel modules to be loaded: "pcspkr" & "snd_pcsp" | |
# also, adjust 'log_files' and 'logtail_offset_dir' accordingly | |
log_files_locations="/var/log/switches/*/switch.log" | |
logtail_offset_dir="/tmp/log-alarm_offset" | |
minutes_to_be_in_noclear_mode=14 | |
################ DO NOT CHANGE THE CODE BELOW ################# | |
## environment stuff ## | |
#set -x | |
mkdir -p $logtail_offset_dir | |
chmod -R a+rw $logtail_offset_dir &> /dev/null | |
iteration=1 | |
very_first_iteration=true | |
noclear_mode=false | |
seconds_between_iterations=20 | |
first_iterations=$(( ($minutes_to_be_in_noclear_mode * 60) / $seconds_between_iterations )) | |
# a countdown time mode after the first number iterations after noclear_mode expires | |
iterations_before_counting=true | |
while true; do | |
if ! $noclear_mode; then clear; fi | |
new_log_output="" | |
for file in $log_files_locations; do | |
new_log_output+="$(logtail -f "$file" -o "$logtail_offset_dir/${file//\//_}.offset")" | |
done | |
if [[ -z "$(echo "$new_log_output" | sed -e 's/^[ \t]*//i')" ]]; then # if there's no new log output | |
if ! $noclear_mode ; then | |
minutes=$(( ($seconds_between_iterations * $iteration) / 60 )) | |
if (( $iteration < $first_iterations )) && ! $very_first_iterations && $iterations_before_counting; then | |
iterations_before_counting=false | |
minutes=$minutes_to_be_in_noclear_mode | |
fi | |
echo -ne " \e[0;32m-------- There's no new log output for the last \e[0;31m$minutes minute(s)\e[0;32m --------\e[0m " | |
fi | |
if $noclear_mode && [ $(($iteration * $seconds_between_iterations)) -gt $((60 * $minutes_to_be_in_noclear_mode)) ]; then | |
# turning off noclear_mode if the iterations time (in seconds) is greater then seconds in noclear_mode allowed | |
noclear_mode=false | |
iteration=0 | |
fi | |
else | |
iteration=0 | |
noclear_mode=true | |
iterations_before_counting=true | |
beep -l 1000 -r 2 -d 100 | |
echo -ne "\n$new_log_output" | |
fi | |
let iteration++ | |
very_first_iteration=false | |
sleep $seconds_between_iterations | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment