LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-05-2007, 05:50 AM   #1
sarajevo
Member
 
Registered: Apr 2005
Distribution: Debian, OpenBSD,Fedora,RedHat
Posts: 228
Blog Entries: 1

Rep: Reputation: 31
Transfering most recent file every time from an directory


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
 
Old 04-05-2007, 06:13 AM   #2
puffinman
Member
 
Registered: Jan 2005
Location: Atlanta, GA
Distribution: Gentoo, Slackware
Posts: 217

Rep: Reputation: 31
ls can sort by time. This will give you the most recent file:

Code:
ls -t | head -n 1
 
Old 04-05-2007, 06:14 AM   #3
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Maybe a stupid question, but is there any information in the name of the files?

jlinkels
 
Old 04-05-2007, 06:36 AM   #4
sarajevo
Member
 
Registered: Apr 2005
Distribution: Debian, OpenBSD,Fedora,RedHat
Posts: 228

Original Poster
Blog Entries: 1

Rep: Reputation: 31
Quote:
Originally Posted by jlinkels
Maybe a stupid question, but is there any information in the name of the files?

jlinkels

this part is the same
rrrrr_....20070404214503...._...44538.....txt

the part between ..... is some kind of time stamping but, I think it is easier to use time in format 21:15


any idea is welcome
 
Old 04-05-2007, 07:07 AM   #5
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
If I understand you correctly, you can NOT use the time stamp of the file which is given by 'ls' because that time stamp changes whenever the file is transferred to that directory.

But the name of the file, and especially the part ...20070404214503... gives information about the time stamp. Is that correct?

jlinkels
 
Old 04-05-2007, 07:34 AM   #6
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
A suggestion. If you have access to the directory that transfers the file to "this" directory, then examine `touch`. It has a "-r ref_file" option. So something like

Code:
cp <SomeDir><ThisFile> <ThisDir><ThisFile>; touch -r <SomeDir><ThisFile> <ThisDir><ThisFile>
may work for you.

This should be folowed by find.

Please post the result.

End
 
Old 04-05-2007, 07:42 AM   #7
sarajevo
Member
 
Registered: Apr 2005
Distribution: Debian, OpenBSD,Fedora,RedHat
Posts: 228

Original Poster
Blog Entries: 1

Rep: Reputation: 31
Quote:
Originally Posted by AnanthaP
A suggestion. If you have access to the directory that transfers the file to "this" directory, then examine `touch`. It has a "-r ref_file" option. So something like

Code:
cp <SomeDir><ThisFile> <ThisDir><ThisFile>; touch -r <SomeDir><ThisFile> <ThisDir><ThisFile>
may work for you.

This should be folowed by find.

Please post the result.

End
Unfortunately, i have not access to these machines which transfer files to this machine ( this directory ) I can only manipulate with files in " my " directory.

Thanks
 
Old 04-05-2007, 07:52 AM   #8
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
You could extract the time stamp from the file name, if as you say, the time information is contained in the file name.

If your file name is: "rrrrr_20070404214503_44538.txt" then something like this should work:

Code:
a=$file_name
time_stamp=$(date +%s -d "${a:6:8} ${a:14:2}:${a:16:2}:${a:18:2}")
It translates the file name into the time in seconds.

jlinkels
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
File transfering mikejac69 LinuxQuestions.org Member Success Stories 5 08-25-2005 04:05 PM
Transfering file lazwaz Programming 1 05-26-2005 04:34 PM
how to grab most recent directory toddcurry Programming 2 05-02-2005 10:33 PM
Transfering file between WinXP and FC2 NeoAndersn007 Linux - Hardware 6 08-15-2004 02:24 PM
transfering a 9gb file BigHead314 Linux - Networking 4 01-03-2004 05:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration