Skip to content

Instantly share code, notes, and snippets.

@clarinet758
Created October 17, 2015 09:49
Show Gist options
  • Save clarinet758/fc1c948dd5dd55bb845f to your computer and use it in GitHub Desktop.
Save clarinet758/fc1c948dd5dd55bb845f to your computer and use it in GitHub Desktop.
#!/bin/bash
target=ntpd
logfile=/var/log/origin.log
function timestamp() {
echo "`date '+%y/%m/%d %H:%M:%S'`"
return $?
}
#echo `timestamp`
#ps -C $chk -o comm= > /dev/null || sudo /usr/sbin/$chk
function res() {
echo `ps -C $target -o comm= | head -n 1`
return $?
}
if [ ${target} = "`res`" ]; then
echo "`timestamp` [$target] status is running" >> $logfile
exit 0
else
echo "`timestamp` [$target] status is error" >> $logfile
echo "`timestamp` [$target] trying start" >> $logfile
service $target start
fi
if [ ${target} = "`res`" ]; then
echo "`timestamp` [$target] status is running" >> $logfile
exit 0
else
echo "`timestamp` [$target] start failed(unknown error)" >> $logfile
#mail....
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment