0

I'm using some casperjs scripts (which I don't really understand) with a known issue that the process hangs after a specific warning message. Otherwise it's outputting a log message every few seconds.

I need to restart the process when it hangs.

So can I make a script which checks if a log file is getting bigger at each time interval? Or can I intercept the console output of a process and check if the last message is the same as the specific warning message?

Any help will be appreciated, thanks!

1 Answers1

0
#!/bin/sh
LOGFILE="/path/to/logfile/"
CURRENT_SIZE=`stat --format "%s" $LOGFILE`
while true; do
    LAST_SIZE=$CURRENT_SIZE
    sleep 10
    CURRENT_SIZE=`stat --format "%s" $LOGFILE`
    if [[ $CURRENT_SIZE -eq $LAST_SIZE ]]; then
            echo "Restarting process"
            #do whatever you need to restart process...
            sleep 5
            CURRENT_SIZE=`stat --format "%s" $LOGFILE`
    fi
done
user1700494
  • 1,642
  • 2
  • 12
  • 21