Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- logline='event reporting instance is not ready to be reused'
- logfile=$(ls -1tr /opt/ang/log/adselect/adselect.log)
- if [[ $(id -u) -ne 0 ]]; then
- echo "${0} has to be executed as root!"
- exit 1
- fi
- # returns adselect running time in epoch
- function get_adselect_run_time() {
- echo $(date "+%s" -d "$(ps -eo time,cmd | grep adselect.fcgi | grep -v grep | sort -k1 -n -r | head -n 1 | awk {'print $1'})")
- }
- # returns timestamp from the last line in $logfile in epoch
- function get_time_from_log() {
- echo $(date "+%s" -d "$(tail -n 1 $logfile | awk '{print $1,$2}')")
- }
- # returns current date in epoch
- function get_current_time() {
- echo $(date "%s")
- }
- # /////////////////////////////////////////////////////////////////////
- # // MAIN
- function main() {
- adselect_restart=0
- adselectrun=$(get_adselect_run_time)
- timefromlog=$(get_time_from_log)
- if [[ $timefromlog -gt $adselectrun ]]; then
- tail -n 20 $logfile | grep "$logline" > /dev/null
- if [[ $? -eq 0 ]]; then
- adselect_restart=1
- fi
- cat $(ls -1t /opt/ang/log/adselect-req9/*.log | tail -n 1) | tail -n 20 | grep 'unimplemented' > /dev/null
- if [[ $? -eq 0 ]]; then
- echo "unimplemented log found"
- adselect_restart=1
- fi
- if [[ $adselect_restart -eq 1 ]]; then
- echo "adselect have to be restarted"
- echo $(hostname)
- echo $(curl -s showip.net;echo)
- service adselect stop
- sleep 3
- service adselect start
- fi
- fi
- }
- main
Add Comment
Please, Sign In to add comment