Skip to content

Instantly share code, notes, and snippets.

@free5ty1e
Last active August 29, 2015 14:11
Show Gist options
  • Save free5ty1e/300adb0800ba45f3fe4e to your computer and use it in GitHub Desktop.
Save free5ty1e/300adb0800ba45f3fe4e to your computer and use it in GitHub Desktop.
bash XRDP log monitor (raspberry pi / raspbian friendly script)
#!/bin/bash
# xrdpLogMonitor.sh <optional timeout in seconds>
# This script will check and spit out your xrdp log file every X seconds
# (default 30 if not specified)
# If the file size has changed since your last check, your terminal will beep (system alert)
logFileName="/var/log/xrdp.log"
if [ $# -eq 0 ];
then
echo "No arguments supplied, will use default time between log polls (30 seconds)"
secondsBetweenLogPolls=30
else
echo "Using supplied timeout of $1 seconds between log polls"
secondsBetweenLogPolls=$1
fi
function updateLogModifiedTimeAndBeepIfChanged()
{
lastLogModifiedTime=$LogModifiedTime
LogModifiedTime="$(stat --printf="%Z" $logFileName)"
if [ "$LogModifiedTime" != "$lastLogModifiedTime" ];
then
echo NEW LOG ACTIVITY CAPTURED!!!!
#Below line creates the terminal beep
echo -ne '\a'
fi
}
while [ 1 -lt 2 ]; do
updateLogModifiedTimeAndBeepIfChanged
echo "$(ls -l $logFileName)"
echo "Polling logfile $logFileName which was last modified at $LogModifiedTime..."
#You will need sudo on the pi to cat this xrdp log
sudo cat $logFileName
#Uncomment the following line to search, for example, for "USER:" and display only those lines that contain it:
#sudo cat $logFileName | grep USER:
echo "$(date) <--- this is now"
sleep $secondsBetweenLogPolls
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment