Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Search Forums:



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-09-2012
Registered User
 

Join Date: Feb 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Copy the newest file from a different server to your home server.

Hi all,

So I am on server 1, and I want to grab the newest file from a particular directory on server 2, and place this in a directory on server 1.

I am trying to use:
Code:
ls -tr | tail -1

This works, and gets me the newest file in a particular directory. Using svn `ls -tr | tail -1` etc I can grab the newest file and copy it somewhere else if the newest file is in the directory i'm currently in.

The problem is using ls -tr | tail -1 in an attempt on server 2, as ls seems to only look in the directory i'm currently in and not in another.

Is there a way I can use that command in a way like this example:

Code:
scp user@host:/directory $foo  where foo=`ls -tr | tail -1`

The $foo here only looks in the directory i'm in, not user@host etc.

Hope this ramble makes sense!!

Alex

---------- Post updated at 07:58 AM ---------- Previous update was at 06:25 AM ----------

Just to add to this.

Code:
[host1]  scp host2@IP:/home/b/files/reports/`ls -tr | tail -1`  host1@IP:/home/b/c/a/A/

Is what I am attempting.

The ls -tr | tail -1 looks in host1, rather than the latest file in the directory ending /reports/...I need a way to grab the latest file from /reports/ and place it in host1.

Moderator's Comments:
Please use next time code tags for your code and data

Last edited by vbe; 02-09-2012 at 09:54 AM..
Sponsored Links
    #2  
Old 02-10-2012
quirkasaurus's Avatar
Registered User
 

Join Date: Jan 2009
Location: canton, michigan
Posts: 481
Thanks: 0
Thanked 7 Times in 7 Posts

Code:

latest_file=$( ssh remote_host /bin/ls -ltR /tmp/\* | head -1 | awk '{ print $9;}' )

scp remote_host:$latest_file .

Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script to check for the newest file mutiple times a day and SCP it to another server. richasmi Shell Programming and Scripting 1 03-01-2011 02:13 PM
Copy file from one server to multiple server alokjyotibal Shell Programming and Scripting 7 11-20-2009 01:20 PM
To copy a file from one unix server to another unix server through scripts manit UNIX for Dummies Questions & Answers 1 09-02-2009 11:49 AM
Command for copy a file from one server to another server sarwan Programming 2 11-13-2005 10:17 AM
home network - can you have a primary name server, or only a caching-only name server xyyz UNIX for Dummies Questions & Answers 3 02-18-2004 12:13 PM



All times are GMT -4. The time now is 03:46 AM.