Solved

Using wget to retrieve the newest file only

Posted on 2013-02-07
2
241 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Postfix issues with spam/auth attempts under NAT 9 84
Steps to follow for Maintenance of Servers 4 63
android secure ftp 3 38
How can i open a .fxp file 3 33
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.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

770 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