Welcome to the new Linux Foundation Forum!

Cron Job

Good day!

How can i check the specific cron job is running? I'm planning to create a script which is do the checking if my cron job is running then if not, the script would execute the cron job again..

Thanks in advance!

God bless you all!

Comments

  • mfillpotmfillpot Posts: 2,180
    You can write a script that used lsof to track if you script file is in use, or ps to track if an application is running, then choose the appropriate actions based upon the results.

    The code below can be used as a base to track if a file is in use and you can adjust the conditional criteria to fit your needs.
    #!/bin/bash                                                                                                                                                                                    
                                                                                                                                                                                                   
    SCRIPT="testscript.sh"                                                                                                                                                                               
                                                                                                                                                                                                   
    if [ -n "$(lsof|grep -i $SCRIPT)" ]; then                                                                                                                                                      
            echo "$SCRIPT is running"                                                                                                                                                              
    else                                                                                                                                                                                           
            echo "$SCRIPT is not running"                                                                                                                                                          
    fi
    
  • Wow! Mr. mfillpot your great..

    it helps me a lot..

    thank you and god bless you!
Sign In or Register to comment.