LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-11-2008, 05:58 PM   #1
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Rep: Reputation: 15
rsync file by newest date


All, i need to rsync a file by the newest date stamp over ssh. The format of the file looks like:
-rw-rw-r-- 1 user user 87 Sept 15 19:59 test.log.2008-09-15

Ive hear you can use find and mtime and then pipe it to rsync. If anyone has an idea how to do this and can give me an example command to use it would be very much appreciated.

Thanks!
 
Old 10-11-2008, 07:47 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
if you only have logfiles in that dir and only one per day, then you should be able to use ls, head


ls -t|head -1

otherwise you could use find + mtime. See man find.
 
Old 10-11-2008, 09:32 PM   #3
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Original Poster
Rep: Reputation: 15
Thanks Chris but i was looking for the rsync command, i know how to ls them command line.
 
Old 10-11-2008, 09:55 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Well, rsync automatically updates/copies any file that has changed/is newer than the corresponding target area, so it should take care or that automatically for you.
One of the main points of rsync is that it only sends differences (by default), so if you have a dir full of logfiles it'll only send the new one(s). You don't have to specify that restriction yourself...

Does that help?
 
Old 10-11-2008, 10:03 PM   #5
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
I'm not sure how to do it with find (I assume you are wanting the only the single most recent file in the directory rsync'ed?)

I like Chris's method. Here's what I did (bu I'm sure you could be slicker:

Code:
latest=`ls -t|head -1` ; rsync $latest ~/temp
Where ~/temp was simply the destination for my test run.

Edit - sorry - was playing with a solution while Chris posted.
 
Old 10-12-2008, 10:44 PM   #6
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Original Poster
Rep: Reputation: 15
Rsync error

well i have the newest part of this issue resolved, now i need help with an error. When i run the below command on the command line it works great:
rsync -av /localdirectory/file.log* userid@remotehost:/remote directory

But when i dump it in expect, because it required a password. This is the only way i can do this, i cant generate keys, etc...


building file list ... rsync: link_stat "localdirectory/server*" failed: No such file or directory (2)
done

Very strange.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find newest file capella Linux - Software 9 04-28-2012 04:26 AM
newest data file wolfindark Linux - Newbie 1 07-04-2008 01:42 AM
shell script to find modified date and last accessed date of any file. parasdua Linux - Newbie 6 04-22-2008 09:59 AM
how to use rsync to update date/time only coontie Linux - Software 2 05-15-2006 11:13 AM
Copying the newest file in a directory to another location Transition Linux - General 2 01-14-2005 11:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration