#!/usr/bin/perl -w
#######################################################
use strict;
use warnings;
use diagnostics;
use FileHandle;
my $fh=new FileHandle("< /var/run/mystamp.txt")
or die "/var/run/mystamp.txt: $!";
my $stamp=<$fh>;
chomp $stamp;
undef $fh;
$stamp += 86400;
$fh=new FileHandle("> /var/run/mystamp.txt")
or die "/var/run/mystamp.txt:$!";
printf $fh "%d\n",$stamp;
undef $fh;
exit(0);
That is an oversimplified IMHO way of doing it and let me
outline some of the issues with this method:
- No file locking. If another instance of this script
starts up then they both will attempt to update the file.
- No checking of the data in the file for validity
Probably other problems, but that's just first pass.
What you didn't say in your post is why you are
doing this in the first place. In your script that uses
epoch time stamps why not use time system call
to generate your epoch stamp?
Peter L. Berghold -- Unix Professional Peter at Berghold dot Net |
| |
Dog trainer, dog agility exhibitor, brewer of
fine Belgian style ales. Happiness is a warm, tired, contented dog curled up at your side and
a good Belgian ale in your chalice. |
|