Capture time of File last created.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Capture time of File last created.
# 1  
Old 10-16-2010
Bug Capture time of File last created.

Hi ..

I have a list of filenames in a particular file. All thse files get generated in the same directory. No w i want to find out which of thse got generated last and capture that time .
Have written a while loop but seems getting struck ...

Code:
while read line
do
if [ -e "${line}" ]
then
rvst_capt_time= `ls -lrt $line | awk {'print$7'}`

# here the logic for comparing the modified tome of files should be thr and store into a variable the time of file which gets created last .

Code:
fi
fi
done < file_list

Any suggestions appreciated :-)

Last edited by ultimatix; 10-16-2010 at 10:23 AM.. Reason: Adding footer
# 2  
Old 10-16-2010
Hi,

I would try something like this:
Code:
#!/usr/bin/env bash

rvst_capt_time=-1
rvst_capt_file=""

while read line
do
if [ -e "${line}" ]
then
last_time=$(stat -c%Y "$line")
if (( last_time > rvst_capt_time)); then
  rvst_capt_time="$last_time"
  rvst_capt_file="$line"
fi
fi
done <file_list
printf "%s %s\n" "$rvst_capt_file" "$(stat -c%y $rvst_capt_file | sed 's/\..*$//')"

Regards,
Birei
# 3  
Old 10-16-2010
Bug

hi

Getting this error


./test.sh: line 12: stat: command not found
./test.sh: line 12: stat: command not found
./test.sh: line 12: stat: command not found
./test.sh: line 12: stat: command not found
./test.sh: line 12: stat: command not found
./test.sh: line 20: stat: command not found


havent haed of the command stat .. though its there on my man page .

I am using Sun slolaris and Korn shell
# 4  
Old 10-16-2010
Hi,

Ok. I'm afraid 'stat' doesn't work in Solaris like in my box. It's not my SO so I can't test it.

I tell this because searched for it and got this page:

Solaris on x86 - Reg: stat command in solaris 10

Perhaps you could try substituting '/opt/sfw/bin/stat' in case of 'stat' in the script, I don't know. Or wait if other person is able to give you another solution.

Regards,
Birei
# 5  
Old 10-16-2010
./test.sh: line 12: /opt/sfw/bin/stat: No such file or directory
./test.sh: line 12: /opt/sfw/bin/stat: No such file or directory
./test.sh: line 12: /opt/sfw/bin/stat: No such file or directory
./test.sh: line 12: /opt/sfw/bin/stat: No such file or directory
./test.sh: line 12: /opt/sfw/bin/stat: No such file or directory
./test.sh: line 20: stat: command not found


can u pls expalin what stat is ecactly doing so that we can get an alternate commad.
# 6  
Old 10-16-2010
You could try something like this:

Code:
perl -lne'
  push @_, (stat)[9];
  print ~~localtime(
    (sort { $b <=> $a } @_)[0]
    ) if eof
  ' infile

# 7  
Old 10-16-2010
Hi,

From the 'man' page:
stat - display file or file system status

Code examples:
Code:
stat -c%Y infile

outputs 1287241215

and
Code:
stat -c%y infile

outputs 2010-10-16 17:00:15.000000000 +0200


In the script I try to read time modifications in seconds of all files of the input, and select which has the biggest number.

Regards,
Birei
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

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

3. Shell Programming and Scripting

Segregate files based on the time they are created

Hi All, I have scenario where I need to zip huge number of DB audit log files newer than 90 days and delete anything older than that. If the files are too huge in number,zipping will take long time and causing CPU spikes. To avoid this I wanted to segregate files based on how old they are and... (2 Replies)
Discussion started by: veeresh_15
2 Replies

4. UNIX for Dummies Questions & Answers

At jobs - created date and time

Hi, I'm running atq for a user and its showing 2 'at' jobs in the queue to start at a later time. > atq Is there any way i can find out the creation date/time of these jobs? and ideally what job created them and what script(s) they are going to run? All i can see is the job number and... (3 Replies)
Discussion started by: finn
3 Replies

5. Shell Programming and Scripting

Files created on specific time

Hello Gurus, I am facing one issue to get a file for a specific time. There are about 300 files created between 6.30 pm to 7.15 pm everyday. Now I wanted only the file which is created on 6.45pm. No other files required. I have used "find" command to get the files, but not getting the expected... (3 Replies)
Discussion started by: pokhraj_d
3 Replies

6. Shell Programming and Scripting

Help on script to capture info on log file for a particular time frame

Hi I have a system running uname -a Linux cmovel-db01 2.6.32-38-server #83-Ubuntu SMP Wed Jan 4 11:26:59 UTC 2012 x86_64 GNU/Linux I would like to capture the contents of /var/log/syslog from 11:00AM to 11:30AM and sent to this info via email. I was thinking in set a cron entry at that... (2 Replies)
Discussion started by: fretagi
2 Replies

7. UNIX for Dummies Questions & Answers

how to know what time one user was created?

I am using RHEL. I wan to know the creation time of one user? which command? (4 Replies)
Discussion started by: cqlouis
4 Replies

8. UNIX for Advanced & Expert Users

File created time

I have lot .log files in a directory.I need to take the one got created today.Is there any way to get the time of creation of a file? (6 Replies)
Discussion started by: yakyaj
6 Replies

9. Shell Programming and Scripting

query for a file created at a particular time

Hi guys I need to find out a file created at 'x' time and the name of the file is rag.rxt 100's of these files are created every minute and i dont know how to find the file created at a particular time. pls help me with the command to search that. thanks in advance (2 Replies)
Discussion started by: ragha81
2 Replies

10. Shell Programming and Scripting

Determine date and time the file was created through shell scripts

Can I determine when the particular file was created, in korn-shell. Can please someone help me. If possible please mail the solution to me. my mail id: bharat.surana@gmail.com (1 Reply)
Discussion started by: BharatSurana
1 Replies
Login or Register to Ask a Question