Created
July 10, 2014 09:08
-
-
Save yashprit/7661b25904c93d53acff to your computer and use it in GitHub Desktop.
Monitor processing running on system, with single argument as process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $EUID != 0 ] | |
then | |
echo "Please run as root" | |
exit | |
fi | |
if [ "$1" == "" ] | |
then | |
echo "No process name provided" | |
exit | |
fi | |
check_process() { | |
echo "`date +%T` : begin checking.... $1" | |
[ `pgrep -n $1` ] && return 1 || return 0 | |
} | |
while [ 1 ]; do | |
check_process "$1" | |
[ $? -eq 0 ] && echo "$ts: not running, restarting..." && `$1 -i > /dev/null` | |
sleep 200 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage, pass single parameter after shell, e.g
sudo bash ./process_monitor.sh dropbox