Script to check and restart a process

From www.ReeltoReel.nl Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

<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>