Solved

Using wget to retrieve the newest file only

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Debug VNC connection on CentOS7 server 22 71
route 2 traffic streams on single NIC 6 37
Where do I learn ES6? 3 51
networking details on centos 6.6 4 53
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…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 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

20 Experts available now in Live!

Get 1:1 Help Now