How can I create a file with current time - 60 minutes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can I create a file with current time - 60 minutes
# 1  
Old 10-05-2005
How can I create a file with current time - 60 minutes

I'm using k-shell in unix and I want to create a file with the current system time - 60 minutes. I know I can use touch to create the file, but I'm having trouble specifying how tell it to use the current time less 60 minutes. Any ideas???
# 2  
Old 10-05-2005
Use this:
Code:
perl -w -e '@mytime=localtime (time - $ARGV[0]); printf "%d%.2d%.2d%.2d%.2d", $mytime[5]+1900,$mytime[4]+1,$mytime[3],$mytime[2],$mytime[1];' 3600

The output of the above command can be used by touch to create a file.

This is part of a script that can find files created in the last few minutes or few hours. That script can be found here.
# 3  
Old 10-05-2005
Thanks. Do you know how I can do this in k-shell instead of pearl?
# 4  
Old 10-05-2005
You only have the date command in ksh and would have to write a script to fiddle with the output of that. The perl version is much easier. Unless you do not have perl installed on your system, I suggest you go with perl.
# 5  
Old 10-05-2005
This needs my datecalc script which is also on this site...
Code:
#! /usr/bin/ksh

alias datecalc=./datecalc
set -A t $(date "+%Y %m %e %H %M")
echo "datecalc -a ${t[0]} ${t[1]} ${t[2]} - 1"
if ((${t[3]})) ; then
        ((t[3]=t[3]-1))
else
        set +A t $(datecalc -a ${t[0]} ${t[1]} ${t[2]} - 1) 23 ${t[4]}
fi
year=${t[0]}
typeset -Z2 t

timestamp=${year}${t[1]}${t[2]}${t[3]}${t[4]}

touch -t $timestamp xfile
ls -l xfile

exit 0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find if create time of last created file in a directory is older than 5 minutes

A process xyz is running and creating file1, file2, file3, .... filen. how do i know if the process has stopped and createtime of the last file (filen) is older than 5 minutes? OS is AIX (3 Replies)
Discussion started by: malaika
3 Replies

2. Shell Programming and Scripting

Check file creation Time minutes and if file older then 5 minutes execute some stuff

Hello all, Info: System RedHat 7.5 I need to create a script that based on the creation time, if the file is older then 5 minutes then execute some stuff, if not exit. I thought to get the creation time and minutes like this. CreationTime=$(stat -c %y /tmp/test.log | awk -F" " '{ print... (3 Replies)
Discussion started by: charli1
3 Replies

3. Shell Programming and Scripting

How to send a file in UNIX through email which is created only 15 minutes before the current time?

I wanted to send an email to the client whenever there is failed record created in a /feed/HR-76/failed folder after processing of feed file. I can find out with the help of below script that what is the new file created but that file didn't make just 15 minutes before. ... (1 Reply)
Discussion started by: puneetkhullar
1 Replies

4. Shell Programming and Scripting

How to extract logs between the current time and the last 15 minutes ?

I want to extract the logs between the current time stamp and 15 minutes before and sent an email to the people configured. I developed the below script but it's not working properly; can someone help me?? I have a log file containing this pattern: Constructor QuartzJob ... (3 Replies)
Discussion started by: puneetkhullar
3 Replies

5. UNIX for Dummies Questions & Answers

Adding hours and minutes to current date (Only to date not to time)

Hi, I want to add some hours and minutes to the current date. For example, if the current date is "July 16, 2012 15:20", i want to add 5 hours 30 minutes to "July 16, 2012 00:00" not to "July 16, 2012 15:20". Please help. Thanks! (4 Replies)
Discussion started by: manojgarg
4 Replies

6. Shell Programming and Scripting

how to create file.txt and add current date in file content

Hey guy, how to make bash script to create foo.txt file and add current date into file content and that file always append. example: today the script run and add today date into content foo.txt and tomorrow the script will run and add tomorrow date in content foo.txt without remove today... (3 Replies)
Discussion started by: chenboly
3 Replies

7. Shell Programming and Scripting

How to find the create time of a file if current date is in next month

Hi All, I want to find the time diffrence between currnt time and "abc.txt" file create time. I have solve that but if the abc.txt file created last month then is there any process to find the difftent? Exp: Create time of abc.txt is "Apr 14 06:48" and currect date is "May 17 23:47".... (1 Reply)
Discussion started by: priyankak
1 Replies

8. Shell Programming and Scripting

Reading Hours and Minutes from file and comparing with current

Hi, Time till when the application should run is indicated in a file. First line is hour and second line is minute. file: 10 55 Means my application should run till 10:55. Now in a shell script, i am trying to make that logic but with no luck. min=`tail -n 1 /file_with_time`... (1 Reply)
Discussion started by: SGD
1 Replies

9. Shell Programming and Scripting

save weather radar to local time-named file every 15 minutes

I think I can do this myself now, but I am always amazed by how people can do things cleaner and simpler than I end up doing... Using cron, I want to save the image found at: http://radar.weather.gov/ridge/Conus/RadarImg/centgrtlakes.gif every 15 minutes to a local file , such as ... (1 Reply)
Discussion started by: brucewestfall
1 Replies

10. UNIX for Advanced & Expert Users

Adding # minutes to current time...

Hi all, Looking for a way to add lets say 10 minutes to the current time output should look like 7:15 AM or 7:15 PM. I know that gdate could do this for me but unfortunately its not available on the system I'm working on. So if any one know any way I can accomplish this using the date command it... (7 Replies)
Discussion started by: gptavares
7 Replies
Login or Register to Ask a Question