The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > Linux > Red Hat
.
google unix.com



Red Hat Red Hat is the world's leading open source technology solutions provider with offerings including Red Hat Enterprise Linux (RHEL), Fedora, open source applications, security and systems management, virtualization, and Services Oriented Architecture (SOA) solutions.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
crontab; copy most recent *.mpg file from local machine to smb storage device julezsht Shell Programming and Scripting 5 06-02-2009 05:24 PM
Copy file from local machine to server? Sepia UNIX for Dummies Questions & Answers 2 05-12-2009 04:41 AM
check for a file on a remote machine Sheema Shell Programming and Scripting 3 12-04-2008 04:43 AM
how to mount a file system of a remote machine to local file system cy163 UNIX for Dummies Questions & Answers 2 01-31-2008 09:04 AM
[FTP]opying of file from remote to local machine sonbag_pspl SUN Solaris 1 08-12-2004 04:15 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-30-2009
me_ub me_ub is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 2
Question To find the LATEST file from a dir on REMOTE machine and SCP to local machine?

Hi All,

URGENT - Please help me form a scipt for this:

I need the LATEST file from a dir on REMOTE machine to be SCP'd to a dir on local machine. (and I need to execute this from local server)

I know that the below cmd is used to find the LATEST file from a dir. But this command is not supported when used inside the SCP command.

To find LATEST file :
Code:
`ls -1r | head -1`
Thanks!
-UB

Last edited by Yogesh Sawant; 07-06-2009 at 02:41 AM.. Reason: added code tags
  #2 (permalink)  
Old 06-30-2009
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
how about:
Code:
file_to_copy=`ssh username@hostname 'ls -1r | head -1'`
echo copying $file_to_copy ...
scp username@hostname:$file_to_copy /local/path
  #3 (permalink)  
Old 06-30-2009
me_ub me_ub is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 2
Thumbs up

Thanks Yogesh; but no luck on this as well.

In precise, I have :

On SERVER1

dir1 contains:
file1
file2
file3 --> latest one

On SERVER2, I need to execute a script that fetchs file3 into dir2.

Thanks.

---------- Post updated at 02:58 PM ---------- Previous update was at 11:53 AM ----------

Yippiee!
After spending so much time doing R&D on this, I finally got an answer for myself! Hope this helps others as well.


On SERVER2, save this as a script and execute:

Code:
latest_file=`ssh IP_ADDR_OF_SERVER1 find /dir1 -type f -mtime -1 -name "file*"`
echo Staring SCP of $latest_file from SERVER1 to SERVER2...
/usr/bin/scp user@IP_ADDR_OF_SERVER1:$latest_file /dir2
echo SCP Completed.

Enjoy.

-UB
  #4 (permalink)  
Old 07-08-2009
raghav1982 raghav1982 is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 101
is there a way to get the files using FTP instead of SSH which is allowed inour source server ??

Thanks
Reply

Bookmarks

Tags
ftp, latest file, local, remote, scp

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0