title: How do I check the exit code of a command executed by flock?
body: <p>Greetings all.  I'm setting up a cron job to execute a bash script, and I'm worried that the next one may start before the previous one ends.  A little googling reveals that a popular way to address this is the <code>flock</code> command, used in the following manner:</p>
  
  <pre><code>flock -n lockfile myscript.sh
  if [ $? -eq 1 ]; then
      echo "Previous script is still running!  Can't execute!"
  fi
  </code></pre>
  
  <p>This works great.  However, what do I do if I want to check the exit code of <code>myscript.sh</code>?  Whatever exit code it returns will be overwritten by <code>flock</code>'s, so I have no way of knowing if it executed successfully or not.</p>