Linux Script to check if process is running and act on the result

前端 未结 7 1826
孤独总比滥情好
孤独总比滥情好 2020-11-29 23:38

I have a process that fails regularly & sometimes starts duplicate instances..

When I run: ps x |grep -v grep |grep -c \"processname\" I will get: <

相关标签:
7条回答
  • 2020-11-30 00:39

    I cannot get case to work at all. Heres what I have:

    #! /bin/bash
    
    logfile="/home/name/public_html/cgi-bin/check.log"
    
    case "$(pidof -x script.pl | wc -w)" in
    
    0)  echo "script not running, Restarting script:     $(date)" >> $logfile
    #  ./restart-script.sh
    ;;
    1)  echo "script Running:     $(date)" >> $logfile
    ;;
    *)  echo "Removed duplicate instances of script: $(date)" >> $logfile
     #   kill $(pidof -x ./script.pl | awk '{ $1=""; print $0}')
    ;;
    esac
    

    rem the case action commands for now just to test the script. the above pidof -x command is returning '1', the case statement is returning the results for '0'.

    Anyone have any idea where I'm going wrong?

    Solved it by adding the following to my BIN/BASH Script: PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

    0 讨论(0)
提交回复
热议问题