title: Run shell script exactly once with cronjob
body: <p>I have a cron job that calls a script that checks for updates once every hour. If there are updates, it will call <code>update.sh</code>, which in turn calls <code>commands.sh</code>. I would like each "new" <code>commands.sh</code> to be run exactly once.</p>
  
  <p>I was thinking of writing to a file each time I run <code>commands.sh</code> with some unique ID of that file. Before running <code>commands.sh</code>, I check if the file contains the ID of <code>commands.sh</code>. If so, don't run it. </p>
  
  <p>Edit - more detail:</p>
  
  <p>cronjob:</p>
  
  <ul>
  <li>fetch from git repo, pull and merge if any changes  </li>
  <li><p>Run <code>update.sh</code>:</p>
  
  <pre><code>#!/bin/sh
  ./commands.sh
  </code></pre></li>
  </ul>
  
  <p>I want <code>./commands.sh</code> to run just once, because next hour, the cron will run again, pull from git, and run <code>update.sh</code> again. Is there some way for each unique <code>./commands.sh</code> to run just once?</p>
  
  <p>After writing that out, maybe the best way is just to only run <code>update.sh</code> if there was a change from the git repo?</p>
  
  <p>This seems like overkill and hard to maintain. Is there a simpler way to write a bash script that only runs one time?</p>