Copy the newest file from a different server to your home server.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Copy the newest file from a different server to your home server.
# 1  
Old 02-09-2012
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:
Mod Comment Please use next time code tags for your code and data

Last edited by vbe; 02-09-2012 at 10:54 AM..
# 2  
Old 02-10-2012
Code:
latest_file=$( ssh remote_host /bin/ls -ltR /tmp/\* | head -1 | awk '{ print $9;}' )

scp remote_host:$latest_file .

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy multiple .txt files from one server to another server

:wall:Hi all, I have two servers : server A and server B Weekly wise i use to receive files to server A to one particular location say /source/location . NOTE: In this location there will be other files also present other than these weekly arrival 18 files. My task : i need a... (7 Replies)
Discussion started by: karmegam
7 Replies

2. Shell Programming and Scripting

Shell script to copy a file from one server to anther server and execute the binary

Hi , Is there any script to copy a files (weblogic bianary + silent.xml ) from one server (linux) to another servers and then execute the copy file. We want to copy a file on multiple servers and run the installation. Thanks (1 Reply)
Discussion started by: Nawrajesh
1 Replies

3. Shell Programming and Scripting

Copy files from Linux server to Windows server

Hi All, I am generating report in a Linux server and once the report is generated the report(.txt file) needs to be automatically saved in a Windows servers. So i am looking for a script to transfer the file automatically from Linux server to Windows server? Please advise. Thanks... (3 Replies)
Discussion started by: arunmanas
3 Replies

4. Shell Programming and Scripting

Copy folder and files from unix server to linux server

We would be migrating unix solaries to Linux redhat. Basically source is unix and target is linux. i would like to copy entire file system unix/source/* to target linux/souce/* but target linux has only folder setup so what ever files copied need to be placed in the linux server with same... (8 Replies)
Discussion started by: balajikalai
8 Replies

5. Shell Programming and Scripting

Script to check for the newest file mutiple times a day and SCP it to another server.

Hi, I need a sample of a script that will check a specific directory multiple times throughout the day, and scp the newest file to another server. Example: current file is misc_file.txt_02272011 (the last part is the date), once that has been secure copied, another one may come in later the... (1 Reply)
Discussion started by: richasmi
1 Replies

6. Shell Programming and Scripting

Copy file from one server to multiple server

can some one help me to write a shell script that copy one file from one server to multiple server ex:suppose i wnt to copy file abc.txt which is in server 1 to server2,server3,server4....:confused: (6 Replies)
Discussion started by: alokjyotibal
6 Replies

7. UNIX for Dummies Questions & Answers

To copy a file from one unix server to another unix server through scripts

I am getting the fallowing error when i am trying to execute the scp commomd in shell script warning: You have no controlling tty. Cannot read confirmation. warning: Authentication failed. Disconnected; key exchange or algorithm negotiation failed (Key exchange failed.). scp2: warning: ssh2... (1 Reply)
Discussion started by: manit
1 Replies

8. Shell Programming and Scripting

copy files from remote server (B) to target server (A)?

Hi All, what is the comand to log off the remote server? I have 2 servers A, B. I need to find all files older than 7 days on server B and copy over to server A. My logic is: login the remote server: ================= ssh hostB cd /data/test find . -mtime -7 -ls | awk '{print... (4 Replies)
Discussion started by: Beginer0705
4 Replies

9. Programming

Command for copy a file from one server to another server

hi, which Command is used for copy a file from one server to another server, please provide the syntax and give one small example... Thanks in advance sarwan (2 Replies)
Discussion started by: sarwan
2 Replies

10. UNIX for Dummies Questions & Answers

home network - can you have a primary name server, or only a caching-only name server

i'm setting up a solaris 9 box to be my home network's DNS server. actually it's up and running, but it's set as a caching-only name server. can i set it up to be the primary name server? what are the advantages if i can set it up to be a primary name server vs. a caching only name server? (3 Replies)
Discussion started by: xyyz
3 Replies
Login or Register to Ask a Question