Script to check and restart a process

From www.ReeltoReel.nl Wiki
Revision as of 16:35, 11 August 2015 by Pvdm (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

<syntaxhighlight lang="bash">

  1. !/bin/bash
  2. -------------------------------------------------------------------------
  3. Copyright (c) 2003 nixCraft project <http://cyberciti.biz/fb/>
  4. This script is licensed under GNU GPL version 2.0 or above
  5. -------------------------------------------------------------------------
  6. This script is part of nixCraft shell script http://en.wikipedia.org/wiki/Shell_script collection (NSSC)
  7. Visit http://bash.cyberciti.biz/ for more information.
  8. Copyright (c) 2010 CyberOrg Info. Modification to watch any process/service
  9. -------------------------------------------------------------------------

RESTART="/etc/init.d/sshd restart" PGREP="/usr/bin/pgrep" processtowatch="sshd" x=1 while [ $x = 1 ]; do # find pid $PGREP ${processtowatch} if [ $? -ne 0 ] then echo "`date` : $processtowatch went down, restarting" >> /var/log/restart.log $RESTART fi sleep 30 done </syntaxhighlight>