Advertisement
sayanriju

Bash Process Monitor Script

Mar 29th, 2015
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.58 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. proclist="firefox gedit xterm" ## List of processes to monitor
  3. for proc in $proclist;do
  4.     pidof  $proc >/dev/null
  5.     if [[ $? -ne 0 ]] ; then
  6.     ## Process 'proc' is NOT running anymore! Do your stuff...
  7.     ## Here we are:
  8.     ## (1) Saving a log with timestamp to /var/log/procmonitor.log (Assuming write permissions on the file)
  9.     ## (2) Using unix mail command to send a email notice (Assuming mail is set up properly)
  10.             echo "[$(date)]: $proc has stopped" | tee -a /var/log/procmonitor.log | mail -s "Process Stopped Notice" receipient@xyz.com
  11.         fi
  12. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement