mercredi 4 décembre 2019

Monitor a log file for a string, in a bash script with functions

I have a bash script that i'm utilizing functions. One of the functions is to run a separate program, that writes to a log file. This separate program can take any where from 45 minutes to 3 hours. I need my bash script to trigger that program, and then check that log file for a string "Ended", meaning that the program is complete, and then move onto another function. I was thinking of checking this every 15 minutes.

Currently in my script, my functions run:

Precheck 1
Precheck 2
Runprogram
checkprogram
makechanges
etc (many other functions)

the "Runprogram" function just triggers that separate program i was referring to. the "checkprogram" function is what i'm needing some help on.

function checkprogram() {
  DATE_STAMP=$(date +%m%d%Y)
  log "Checking if sepprogram is complete"
    complete="Ended"
    End=$(grep -oh "Ended" /opt/rsi/tmp/*sepprogram.log)
       if [[ ${complete} != ${End} ]]; then
         log "Other program is complete, moving on"
       return
       else
         err "Other program is still running."
       fi

Right now, it isn't checking over and over until that string is found. It just sort of stops.

How can i get this to keep checking that log file, and not halt the script, until that string is found, and then move onto my next function?

Aucun commentaire:

Enregistrer un commentaire