title: Exit script if a file doesn't exist
body: <p>I try to calculate time differences between two log, but when there is no log in logfile, unix takes own birthdate 1970. My script is below. I want to exit from script if there is no log in logfile.</p>
  
  <pre><code>#!/bin/bash
  a=`tail -n 1 /var/log/nginx/error.log | awk -F" " '{print $1" "$2}' | cut -c12-20`
  f=`date '+%Y-%m-%d %H:%M:%S' | cut -c12-19`
  VAR1=$(date -u --date="$a sec UTC" +%s)
  VAR2=$(date -u --date="$f sec UTC" +%s)
  DIFF2=$(( $VAR2 - $VAR1 ))
  if [ $DIFF2 -lt 59 ]; then
  echo "ok"
  else
  echo "nok"
  fi
  </code></pre>