Solved

Using wget to retrieve the newest file only

Posted on 2013-02-07
2
231 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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now