|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
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.
Last edited by vbe; 02-09-2012 at 09:54 AM.. |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
Code:
latest_file=$( ssh remote_host /bin/ls -ltR /tmp/\* | head -1 | awk '{ print $9;}' )
scp remote_host:$latest_file . |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|