LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-12-2011, 03:53 AM   #1
eduard
LQ Newbie
 
Registered: Jul 2011
Posts: 5

Rep: Reputation: Disabled
shell script to copy files


Hi everybody,

I need help to copy files from one CentOS system to another one.
The files are generated automatically at one server, and i want to copy them immediately to an other server.
Please can anybody help me?
 
Old 07-12-2011, 04:35 AM   #2
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 103Reputation: 103
Lightbulb


You just need to use the -u switch to copy over just the new files.

Quote:

#! /bin/bash

cp -u source destination



Set up cron to run every 5 minutes

crontab -e (as the user who should run .. maybe root)

Quote:


# m h dom mon dow command
5 * * * * /path/to/script


Hope this helps.
 
1 members found this post helpful.
Old 07-12-2011, 08:43 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,496

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
Maybe even have a look at rsync
 
Old 07-12-2011, 09:44 AM   #4
eduard
LQ Newbie
 
Registered: Jul 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jv2112 View Post

You just need to use the -u switch to copy over just the new files.





Set up cron to run every 5 minutes

crontab -e (as the user who should run .. maybe root)




Hope this helps.
I will give it a try.
Thanks.
 
Old 07-12-2011, 08:56 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,357

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
Actually, cp will NOT work between systems unless the disks are exported/shared; it only works on 'local' file systems.
For a remote cp, try scp (or rsync as above).
 
Old 07-12-2011, 10:00 PM   #6
roger_heslop
Member
 
Registered: Oct 2009
Location: Leander, TX
Distribution: Fedora 20
Posts: 97

Rep: Reputation: 35
You can use SCP and passwordless login, in conjunction with cron as mentioned above to get this working. I did a write up on this a few weeks ago, you can see it here:

http://thehomelab.blogspot.com/2011/...utomation.html
 
Old 07-13-2011, 03:12 AM   #7
eduard
LQ Newbie
 
Registered: Jul 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Wow, i didn't expect these fast replays.
I am very new here and very surprised.
Thank you very much all of you.

We share, because we care.
 
Old 07-13-2011, 05:31 AM   #8
dhaval thakar
LQ Newbie
 
Registered: Sep 2005
Location: Mumbai, India
Distribution: Fedora / CentOS
Posts: 1

Rep: Reputation: 0
i recommend rsync over scp
 
Old 07-13-2011, 02:13 PM   #9
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,093

Rep: Reputation: 197Reputation: 197
Quote:
Originally Posted by eduard View Post
...immediately to an other server.
Do actually mean immediately? As in as soon as they are created on one server they must be visible on the other server with no delay? If so then assuming the machines on the same LAN put the files that are being created in their own location and then export that location with NFS (limit the export to the IP address of the other server). Then mount the exported filesystem on the other server (probably mount it read-only unless you really need the other sever to alter the files). You could go a step further and use something like ionotify on the other server to detect the creation of files and trigger a script to do something with them.

If you don't really mean immediately then just periodically copy the files using rsync with ssh keys called from a cronjob as others have suggested.
 
Old 07-13-2011, 03:26 PM   #10
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,111

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
i like sshfs.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] shell script to copy newly changed files with rsync genderbender Programming 15 04-22-2010 07:27 AM
SHELL SCRIPT to copy files from cdrom begin_learn Linux - Newbie 2 06-10-2009 08:10 PM
Shell Script to copy and number files extasic Programming 1 12-12-2008 06:29 AM
copy directories and files recursively using C shell or bash shell bostonuser Programming 7 06-06-2008 01:24 AM


All times are GMT -5. The time now is 08:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration