The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Source and Target count checking ksmbabu Shell Programming and Scripting 2 04-03-2008 04:57 AM
shell script to transfer files from Unix to Windows knag Shell Programming and Scripting 15 12-05-2006 05:46 PM
Tar files, transfer to remote host and delelte source Dago SUN Solaris 0 02-28-2006 05:35 PM
Transfer files from Unix server to Windows using FTP gjsaravanan UNIX for Dummies Questions & Answers 1 08-22-2005 08:55 PM
vi, c/source/target g? yls177 UNIX for Dummies Questions & Answers 7 12-02-2002 11:46 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-16-2009
radhirk radhirk is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 8
Shell script to transfer the files from source to target server.

I need to write a shell script to transfer the files every hour from source - target server.
The cron job should be running every hour and shouldn't copy already copied files to the remote server ?

I was able to write intial script but not able to get the logic for (in the next run it should copy only newly created files with in that hour)

Here is the logic:-
for I in `ls`
do
echo $I - Log from cron
scp $I pluto@5.67.16.25:$REMOTE_LOC/
sleep 120
done


Thanks,
  #2 (permalink)  
Old 01-16-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,311
When you transferred your files, just move them or rename them if possible so they will not be transferred again.
If these files may not be renamed or moved to another location, copy them from their original location to some "transfer" directory and store them there.
To save some space, you can also just write into some txt-file, which files you just transfered and filter them out to not transfer them again by checking if their names are already in the list.
There is a lot of possibilities how to do that.

Best write with [ code ] tags when displaying code, data or logs etc.
  #3 (permalink)  
Old 01-16-2009
angheloko's Avatar
angheloko angheloko is offline
Registered User
  
 

Join Date: Jul 2008
Location: Philippines
Posts: 125
Maybe you can...

For the succeeding steps, why not use find instead of ls in filtering the files that needs to be copied, that way you can use the -mtime (can be used filter files based on the last mod time), -name, -type and other useful flags
  #4 (permalink)  
Old 01-16-2009
Rhije Rhije is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 103
Why not just use rsync? It can be a bit confusing.. but very very configurable!
  #5 (permalink)  
Old 01-16-2009
radhirk radhirk is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 8
Here I can move the files on remote server to a different directory.
But how come the local server knows that it shouldn't transfer already transferred files in the next hour run ? The files that gets created are 500 MB each time.

here how can I use the filter command ?


Thanks,
Radhika.
  #6 (permalink)  
Old 01-16-2009
Rhije Rhije is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 103
hrm.. I would try using 'touch' to modify the access time.

Old files, touch them to be a year ago, new files, touch them to be NOW. And so you can easily see which ones are which.
  #7 (permalink)  
Old 01-16-2009
radhirk radhirk is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 8
Hi angheloko,
why not use find instead of ls in filtering the files that needs to be copied, that way you can use the -mtime (can be used filter files based on the last mod time), -name, -type and other useful flags


I know using the mtime with days (number of days). I don't know how to use modified time like for the past 1 hour,2 hours ?

Could you please give me a hint on this ?

Thanks,
Radhika.
Closed Thread

Bookmarks

Tags
mtime

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 12:57 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