title: Adding time stamp to log file in bash script
body: <p>My script is as follows</p>
  
  <pre><code>if ps ax | grep -v grep | grep ./program &gt; /dev/null
      then
          exit
      else
          echo "---------------------------------------------------" &gt;&gt; Debug.log
          echo "Starting program at:  $(date)" &gt;&gt; Debug.log
          ./program &gt;&gt; Debug.log 2&gt;&amp;1
  fi
  exit
  </code></pre>
  
  <p>Via crontab, this script is run every minute. It checks to see if a certain program is running, if it is, great, if not, starts it up.</p>
  
  <p>Now I would like to append timestamps every time the script runs into Debug.log if it found ./program to be running. So under the <code>then</code> line, I added:</p>
  
  <pre><code>echo "Time: $(date)" &gt;&gt; Debug.log
  </code></pre>
  
  <p>This command does not output anything to Debug.log. It does work however directly from the command line. Why is that so, and can I remedy the problem?</p>