Solved

Using wget to retrieve the newest file only

Posted on 2013-02-07
2
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

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.
Fine Tune your automatic Updates for Ubuntu / Debian
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

729 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