Re: Increment counter upon each execution of shell script



Thank you all for your help. I will try out the things you recommended
and hope at least one of them does what I need it to do.

The reason for this counter is that the way that the files that I wish
to get from a remote server are named is something like the following:
SYSTEM.LOGFILE.G4401V00. Every day, there's a new file that gets
added, where the G4401 becomes G4402, etc. So I was thinking of
keeping a counter in a separate file that would do this incrementation
and then concatenate the strings to form the entire file name. Please
let me know if you think this approach is a reasonable one and if not,
any suggestions are more than welcome.

Thanks

On Jun 27, 6:16 pm, phil-news-nos...@xxxxxxxx wrote:
On Fri, 27 Jun 2008 03:18:52 +0100 Ben Bacarisse <ben.use...@xxxxxxxxx> wrote:

| You need a file to store the counter, like this:
|
|  #!/bin/bash
|
|  read COUNT <counter
|  echo $COUNT
|  echo $((COUNT+1)) >counter

My preference would be to do:

read COUNT <counter
echo $COUNT
echo $((COUNT+1)) >counter.$$
mv -f counter.$$ counter || exit 1

Even that won't ensure a correct count.  It should at least avoid corrupting
the counter if there is more than one process involved.

--
|WARNING: Due to extreme spam, googlegroups.com is blocked.  Due to ignorance |
|         by the abuse department, bellsouth.net is blocked.  If you post to  |
|         Usenet from these places, find another Usenet provider ASAP.        |
| Phil Howard KA9WGN (email for humans: first name in lower case at ipal.net) |

.



Relevant Pages

  • Re: Newbie Three
    ... echo "tesgform"; ... echo "suspected alien invasion case topic table"; ... echo "suspected alien invasion unknown group name"; ...
    (comp.lang.php)
  • Newbie Three
    ... echo "tesgform"; ... echo "suspected alien invasion case topic table"; ... echo "suspected alien invasion unknown group name"; ...
    (comp.lang.php)
  • ToDo list utility - suggestions/optimizations/refinements wanted
    ... For the past couple of days, I've been working on this todo list script and I'm really happy with the way it works, but wanted to post it here before I go any futher, in case anybody had suggestions for optimizations or style errors. ... echo "File written successfully." ...
    (comp.unix.shell)
  • Re: Apple Remote Desktop root vulneravility
    ... If you are trying to run a remote install script such as the Adobe Silent installer, use the lock screen feature in ARD. ... # umount any previous mounted installer images ... trap 'cd "$"' EXIT ... echo "This version of MacOS is not supported." ...
    (Bugtraq)
  • Re: Shell Script to Remove Old Files
    ... Note it needs a TSM server: ... # Verify command line arguments ... echo "\nError: $STARTDIR does not exist.\n" ...
    (comp.unix.admin)