Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transfering most recent file every time from an directory 1

Status
Not open for further replies.

gargamel100

Technical User
Oct 25, 2006
31
CZ
HI all,

I need your help if someone can can help :)

In an directory I have

-rw-r--r-- 1 ggggg ggggg 196846 2007-04-04 19:46 rrrrr_20070404214503_44538.txt
-rw-r--r-- 1 ggggg ggggg 192037 2007-04-04 20:02 rrrrr_20070404220002_44539.txt
-rw-r--r-- 1 ggggg ggggg 182503 2007-04-04 20:16 rrrrr_20070404221503_44540.txt
-rw-r--r-- 1 ggggg ggggg 162382 2007-04-04 20:32 rrrrr_20070404223003_44541.txt
-rw-r--r-- 1 ggggg ggggg 168154 2007-04-04 20:46 rrrrr_20070404224502_44542.txt
-rw-r--r-- 1 ggggg ggggg 161118 2007-04-04 21:02 rrrrr_20070404230002_44543.txt
-rw-r--r-- 1 ggggg ggggg 151536 2007-04-04 21:16 rrrrr_20070404231502_44544.txt

using this
ls -l | awk '{if ( $8~/^ggggg/ ) print $6 "\t" $7 "\t" $8 }'
I can filter date, time and filename. Every 14 min from one machine, and every 16 min from other machine I got new file, as above, but time stamp is different, part 21:02, 21:16 and so on. I need to find out some solution how transfer most recent file from this directory to another machine using ftp. FTP implementation is not problem,and when I write script I will put it in cron table to run every 20 min and fetch last file transfered to that directory. But I can not realise my how select last recent file, in directory, because time parameter is changing every time the file is transfered to this directory. If anybody has some hint to direct, it would be very helpful.
I can use awk and shell scripting tools.

best wishes and regards

Gargamel100
 
Not sure if I fully understood your requirements...
I think you are looking for a way to find the newest file in a directory, right?

Well, this is awk forum, but I wouldn't use awk for this part.
What about this:
ls -rtl | tail -1

regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top