LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 03-28-2004, 12:34 AM   #1
kd5giv
LQ Newbie
 
Registered: Mar 2004
Distribution: Slackware Lastest
Posts: 18

Rep: Reputation: 0
How to get last file written to directory


Hello,
Suppose I want the last file written to an ftp directory. Does anybody know how to write a script to get the latest file from an ftp directory.

There is 250 or so files in that directory. It's weather radar data files for some software I use to plot it. Since the National Weather Service didn't make file names that are named as dates or make a symbolic link called latest, I can't get the files by file name. So I need to get the latest file by when it was put in the directory.
If I don't have the right ftp client I can get it, but I usually use wget or ncftp that came with Slackware 9.1.

Thanks for listening to my long story.
 
Old 03-28-2004, 06:45 AM   #2
Oliv'
Senior Member
 
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36
Hello,

to sort file by date, you can use: ls -t
So what you can do is a script which connect you with ssh, then list file by date and grep the good ones... you put their address in a file and thanks to wget -i, you can retrieve your files

oliv'
 
Old 03-28-2004, 06:36 PM   #3
kd5giv
LQ Newbie
 
Registered: Mar 2004
Distribution: Slackware Lastest
Posts: 18

Original Poster
Rep: Reputation: 0
Well what you said helped some. I now have the ls -lt. Now I am having problems with grep. I've never run grep. Maybe I can get some help with grep now. Here is the listing I need to be put into a file:

-rw-r--r-- 1 1 18406 Mar 28 22:07 sn.0232

I need the sn.0232 at the end of the list there into a file for wget to use. I thought of using 'cut' but it cut the last few letters of the whole directory. That output above is from the second line. of ls -tl. Using cut I did 'cut -b 52-63' or something like that.
Thanks oliv' for your help though.
 
Old 03-29-2004, 06:46 AM   #4
Oliv'
Senior Member
 
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36
Hi,

So I suppose that you need to download file of the current day... 'cause when you run "grep" command you need to match a pattern and as you may not know filename by advance, we'll do work on the date
So to have the date in the same format as "ls -l" command, the command is "date +%b\ %d" (the \ is required to protect space character)... So the command to list the files created the current day is:
Code:
ls -lt | grep "$(date +%b\ %d)"
then you can run "cut" command to only keep filename and redirect the result into your file

Oliv'
 
Old 03-29-2004, 02:26 PM   #5
kd5giv
LQ Newbie
 
Registered: Mar 2004
Distribution: Slackware Lastest
Posts: 18

Original Poster
Rep: Reputation: 0
Thanks for the help on this subject. I found a short cut for this problem. the command:
ncftpls -xt ftp://tgftp.nws.noaa.gov/SL.us008001...p19r0/SI.kfws/ | head -1 > outfile
gets the latest file name output to the file named 'output'
This post is in case somebody is looking for the same problem later and does a search for questions already asked.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
libtermcap.so.2: cannot open shared object file: No such file or directory tcma Linux - Software 11 02-24-2012 03:00 AM
reading file written by shell using C kapil_dev Programming 9 09-10-2005 12:11 AM
awk: fatal:cannot open file for reading (no such file or Directory) in Linux sangati vishwanath Linux - Software 4 07-06-2005 12:59 AM
libawt.so: libXp.so.6: cannot open shared object file: No such file or directory man26 *BSD 0 09-10-2004 08:34 AM
The file or directory file:/misc/cdrom does not exist rangerssg Linux - Newbie 5 08-29-2004 05:17 AM


All times are GMT -5. The time now is 07:16 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration