Skip to content

Instantly share code, notes, and snippets.

@tomer
Last active August 29, 2015 14:01
Show Gist options
  • Save tomer/03202ce93b7ce2e03632 to your computer and use it in GitHub Desktop.
Save tomer/03202ce93b7ce2e03632 to your computer and use it in GitHub Desktop.
Send ps report after system restart (set as cron job to run every few minutes)
#!/bin/bash
a=`cat /proc/uptime | cut -f 1 -d "."`
b=`cat ~/previous_uptime | cut -f 1 -d "."`
cp /proc/uptime ~/previous_uptime -f
if [ "$a" -gt "$b" ]; then
# Regular behavior - Incremental times
echo >> ~/uptime_report.txt
echo >> ~/uptime_report.txt
date >> ~/uptime_report.txt
uptime >> ~/uptime_report.txt
ps aux >> ~/uptime_report.txt
echo Report created!
else
# System was restarted!
echo | mail user@example.net -A ~/uptime_report.txt -s "`hostname` process report"
rm ~/uptime_report.txt
echo Message sent!
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment