- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Create file with date minus number of seconds
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-17-2010 01:18 AM
тАО02-17-2010 01:18 AM
Create file with date minus number of seconds
I need to create file with specified timestamp - like -1800 second backwards from now.
In linux:
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@....
Any help?
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-17-2010 01:26 AM
тАО02-17-2010 01:26 AM
Re: Create file with date minus number of seconds
Hope this Helps .... :)
http://forums11.itrc.hp.com/service/forums/questionanswer.do?admit=109447626+1266398671869+28353475&threadId=1280246
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-17-2010 01:30 AM
тАО02-17-2010 01:30 AM
Re: Create file with date minus number of seconds
Here is how to assign points:
http://forums.itrc.hp.com/service/forums/helptips.do?#33
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-17-2010 01:48 AM
тАО02-17-2010 01:48 AM
Re: Create file with date minus number of seconds
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-17-2010 04:57 AM
тАО02-17-2010 04:57 AM
Re: Create file with date minus number of seconds
Perl gets you what you want:
# cat ./mycreate
#!/usr/bin/perl
use strict;
use warnings;
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";
close $fh;
$at = $mt = time();
utime( $at, $mt - 1800, $file );
1;
...This code prevents you from truncating an existing file. It creates a file 1,800 seconds old if one doesn't already exist.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-17-2010 05:16 AM
тАО02-17-2010 05:16 AM
Re: Create file with date minus number of seconds
But there any method to do it without perl ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-17-2010 06:12 AM
тАО02-17-2010 06:12 AM
Re: Create file with date minus number of seconds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-17-2010 06:17 AM
тАО02-17-2010 06:17 AM
Re: Create file with date minus number of seconds
> 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.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-17-2010 06:30 AM
тАО02-17-2010 06:30 AM
Re: Create file with date minus number of seconds
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: :-)
touch foo
sleep 1800
This works if you are going to have a cronjob that fires off every half hour. You do the touch the previous cycle.