title: linux bash script: set date/time variable to auto-update (for inclusion in file names)
body: <p>Essentially, I have a standard format for file naming conventions.  It breaks down to this:</p>
  
  <pre><code>target_dateUTC_timeUTC_tool
  </code></pre>
  
  <p>So, for instance, if I run tcpdump on a target of 'foo', then the file would be <code>foo_dateUTC_timeUTC_tcpdump</code>.  Simple enough, but a pain for everyone to constantly (and consistently) enter... so I've tried to create a bash script which sets system variables like so:</p>
  
  <pre><code>FILENAME=$TARGET\_$UTCTIME\_$TOOL
  </code></pre>
  
  <p>Then, I can just call the variable at runtime, like so:</p>
  
  <pre><code>tcpdump -w $FILENAME.lpc
  </code></pre>
  
  <p>All of this works like a champ.  I've got a menu-driven .sh which gives the user the options of viewing the current variables as well as setting them... file generation is a breeze.  Unfortunately, by setting the date/time variable, it is locked to the value at the time of creation (naturally).  I set the variable like so:</p>
  
  <pre><code>UTCTIME=$(/bin/date --utc +"%Y%m%d_%H%M%Z")
  </code></pre>
  
  <p>What I really need is either a way to create a variable which updates at runtime, or (more likely) another way to skin this cat.</p>
  
  <p>While scouring for solutions, I came across a similar issues... like <a href="https://stackoverflow.com/questions/11113548/how-to-define-a-auto-update-date-variable-in-bash">this</a>.</p>
  
  <p>But, to be honest, I'm stumped on how to marry the two approaches and create a simple, distributable solution.  </p>
  
  <p>.sh file is posted via pastebin, <a href="http://pastebin.com/G7hic45J" rel="nofollow noreferrer">here</a>.</p>