Solved

Using wget to retrieve the newest file only

Posted on 2013-02-07
2
244 Views
Last Modified: 2013-02-11
Hi,
I'd like to use wget (or something similar) to get newest file from remote location.

The remote folder has files named this way:

1stFILENAMEPARTtimestamp2ndFILEMANEPART.xxx

FILENAMEPART1 (and 2) -parts are allways the same.
timestamp -part chandes: i.e. FILENAMEPART_1_201302071210472ndFILENAMEPART2.xxx
(timestamp = yyyymmddhhmmss)

I'm only interest in the newest one.

What would be the easiest way to get it?
0
Comment
Question by:veli-pekka
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 250 total points
ID: 38863464
If you have ssh/scp access to the remote server this simple one-liner should work:

scp user@remote:$(ssh user@remote ls /remote/dir/FILENAMEPART* | sort |tail -1)  /local/dir/



wmp
0
 
LVL 3

Assisted Solution

by:dibbz
dibbz earned 250 total points
ID: 38863479
I'd suggest lftp because wget doesn't appear to give directory listings.

quick and dirty in bash/lftp;
lftp sftp://user:pass@the.host/path -e "get `lftp sftp://user:pass@the.host/path -e "ls ; exit" | grep FILENAMEPART_1 | sort -t" " -k 1.16,1.30nr | head -n1 | tr -s " " | cut -d" " -f9`"
lftp sftp://user:pass@the.host/path -e "get `lftp sftp://user:pass@the.host/path -e "ls ; exit" | grep FILENAMEPART_2 | sort -t" " -k 1.16,1.30nr | head -n1 | tr -s " " | cut -d" " -f9`"

FILENAMEPART_1_201302071210472ndFILENAMEPART2.xxx
1.16,1.30nr in the sort command means the range that is the date stamp in reverse order

Otherwise I'd use curl if it was for serious businesses with more logic / scripting / web.

Also you don't mention protocol.. lftp will do most just substitute sftp with http/ftp in the example.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question