Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does set -e cause my script to exit when it encounters the following?
    primarykey
    data
    text
    <p>I have a bash script that checks some log files created by a cron job that have time stamps in the filename (down to the second). It uses the following code:</p> <pre><code>CRON_LOG=$(ls -1 $LOGS_DIR/fetch_cron_{true,false}_$CRON_DATE*.log 2&gt; /dev/null | sed 's/^[^0-9][^0-9]*\([0-9][0-9]*\).*/\1 &amp;/' | sort -n | cut -d ' ' -f2- | tail -1 ) if [ -f "$CRON_LOG" ]; then printf "Checking $CRON_LOG for errors\n" else printf "\n${txtred}Error: cron log for $CRON_NOW does not exist.${txtrst}\n" printf "Either the specified date is too old for the log to still be around or there is a problem.\n" exit 1 fi CRIT_ERRS=$(cat $CRON_LOG | grep "ERROR" | grep -v "Duplicate tracking code") if [ -z "$CRIT_ERRS" ]; then printf "%74s[${txtgrn}PASS${txtrst}]\n" else printf "%74s[${txtred}FAIL${txtrst}]\n" printf "Critical errors detected! Outputting to console...\n" echo $CRIT_ERRS fi </code></pre> <p>So this bit of code works fine, but I'm trying to clean up my scripts now and implement set -e at the top of all of them. When i do it to this script, it exits with error code 1. Note that I have errors form the first statement dumping to /dev/null. This is because some days the file has the word "true" and other days "false" in it. Anyway, i don't think this is my problem because the script outputs "Checking xxxxx.log for errors." before exiting when I add set -e to the top.</p> <p>Note: the $CRON_DATE variable is derived form user input. I can run the exact same statement from command line "$./checkcron.sh 01/06/2010" and it works fine without the set -e statement at the top of the script. </p> <p>UPDATE: I added "set -x" to my script and narrowed the problem down. The last bit of output is:</p> <pre><code>Checking /map/etl/tektronix/logs/fetch_cron_false_010710054501.log for errors ++ cat /map/etl/tektronix/logs/fetch_cron_false_010710054501.log ++ grep ERROR ++ grep -v 'Duplicate tracking code' + CRIT_ERRS= [1]+ Exit 1 ./checkLoad.sh... </code></pre> <p>So it looks like the problem is occurring on this line:</p> <pre><code>CRIT_ERRS=$(cat $CRON_LOG | grep "ERROR" | grep -v "Duplicate tracking code") </code></pre> <p>Any help is appreciated. :)</p> <p>Thanks, Ryan</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload