Automated FTP script to grab ONLY newest dated files
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
First off, I recommend using the ncftp suite for all things ftp via a command line or shell script. Almost all distros have an ncftp package in them somewhere & if they don't, it's freely available and very easy to install from their website.
Option 1:
Do you know the date for which you'll be downloading? In other words, will it always be a file called log.`today's date`.tar.gz? If so, then you can always just get that particular file:
Thank you for the assistance BrianK ... I'm unfamiliar with tcsh, but i'll play around with it a bit ... either way, it's very helpful. You're right about ncftp ... much more versatile than the standard ftp client.
As for the today's date problem, i forgot to mention there's a 48 hour lag time in when the logs get posted.
So, logs for the 17th won't be posted until some arbitrary time on the 19th ... hence why I couldn't use the exact date/time variables and had to find a way so that only the newest log was downloaded. But either way, every file is the exact same format ... so, on the 19th I will get a log called log.20061017.tar.gz. This is something determined by our CDN, and I have no control over it.
Isn't there a "get" flag you can use to only grab the newest file added?
Thank you for the assistance BrianK ... I'm unfamiliar with tcsh, but i'll play around with it a bit ... either way, it's very helpful. You're right about ncftp ... much more versatile than the standard ftp client.
As for the today's date problem, i forgot to mention there's a 48 hour lag time in when the logs get posted.
So, logs for the 17th won't be posted until some arbitrary time on the 19th ... hence why I couldn't use the exact date/time variables and had to find a way so that only the newest log was downloaded. But either way, every file is the exact same format ... so, on the 19th I will get a log called log.20061017.tar.gz. This is something determined by our CDN, and I have no control over it.
Isn't there a "get" flag you can use to only grab the newest file added?
(you may even be able to get away without using the backticks if that makes ya feel better)
AFAIK, There's no flag on the get side... All the non-interactive ncftp tools are pretty dumb (by design). Use them in conjunction with one another to get done what you want to get done.
edited to add:
If you're more comfortable, you can always assign the day of the date to a variable then subtract 2. Just be sure to padzero the date for those days < 10. That said, it sure seems easier to ncftpls & get the most recent file.
sweet ... it worked more or less ... I had to add an awk '{print 9}' to it so it would grab the column with the file instead of the entire output line of ls -latr. thanks again though!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.