02-17-2010 01:18 AM
I need to create file with specified timestamp - like -1800 second backwards from now.
touch -t `date \"+%Y%m%d%H%M\" -d@\`echo $((\\`date +%s\\`-1800))` file
will create file with time -1800 seconds. But date in hpux dont have -d@....
02-17-2010 01:26 AM
Hope this Helps .... :)
02-17-2010 01:30 AM
Here is how to assign points:
02-17-2010 01:48 AM
But i need to create file like this:
touch -t aaaaaa file
where aaaaa is time minus -1800 seconds.
I neet to do this automatically.
02-17-2010 04:57 AM
Perl gets you what you want:
# cat ./mycreate
my $file = shift or die "filename expected\n";
my ( $fh, $at, $mt );
die "'$file' already exists\n" if -f $file;
open( $fh, ">", $file ) or die "$!\n";
$at = $mt = time();
utime( $at, $mt - 1800, $file );
...This code prevents you from truncating an existing file. It creates a file 1,800 seconds old if one doesn't already exist.
02-17-2010 06:17 AM
> But there any method to do it without perl ?
Why? Perl is a simple way to accomplish your goal. You could fiddle with a shell script and calculate 1800 seconds (30 minutes) less than the current date/time and build a string representation of the timestamp to use a the argument to 'touch'. To me, that's the hard way.
02-17-2010 06:30 AM
You could write a trivial C program to do it.
Or you could do complex date arithmetic in the shell that handles previous minutes, hours, days, months and years and handles leap years.
Or you could do: :-)
This works if you are going to have a cronjob that fires off every half hour. You do the touch the previous cycle.