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 06-07-2010, 12:43 AM   #1
meandsushil
Member
 
Registered: Feb 2010
Posts: 143

Rep: Reputation: 14
Unhappy How to copy 3 dir's contents to 1 dir by crontab?


how to copy 3 dir's content to 1 dir by crontab?

suppose i want to copy /home/ftp1/* /home/ftp2/* /home/ftp3/* to /ftpdata

three ftp user data to one folder after every one minute by crontab method


so it goes like

*/1 * * * * /bin/cp -rf ??????????? /ftpdata

please tell me.

 
Old 06-07-2010, 12:52 AM   #2
Basse1
LQ Newbie
 
Registered: Jun 2010
Location: India
Posts: 14

Rep: Reputation: 1
Quote:
Originally Posted by meandsushil View Post
how to copy 3 dir's content to 1 dir by crontab?

suppose i want to copy /home/ftp1/* /home/ftp2/* /home/ftp3/* to /ftpdata

three ftp user data to one folder after every one minute by crontab method


so it goes like

*/1 * * * * /bin/cp -rf ??????????? /ftpdata

please tell me.


Create a file test and add write down the 3 commands in that file.

cat /root/test1

#!/bin/bash
Commands_goes_here

Now set the cron as

*/1 * * * * /root/test1
 
Old 06-07-2010, 01:34 AM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,251

Rep: Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026
You require a regex to do it in one cmd eg

Code:
cp dir[1-3] target
 
1 members found this post helpful.
Old 06-07-2010, 02:38 AM   #4
meandsushil
Member
 
Registered: Feb 2010
Posts: 143

Original Poster
Rep: Reputation: 14
Thanks I could do this by above given copy command but could you please tell me how to do this with scripting?

I mean how to copy dir /home/ftp1 /home/ftp2 /home/ftp3 to /ftpdata directory?
 
Old 06-07-2010, 02:44 AM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,251

Rep: Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026
You just make that part of your script. Adjust the names as reqd. Scripts and manual cmds are the same; see
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
http://rute.2038bug.com/index.html.gz
 
Old 06-07-2010, 12:26 PM   #6
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,244

Rep: Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475
Quote:
Originally Posted by meandsushil View Post
Thanks I could do this by above given copy command but could you please tell me how to do this with scripting?

I mean how to copy dir /home/ftp1 /home/ftp2 /home/ftp3 to /ftpdata directory?
You've got the command. Put it in a file, make the file executable. That's it....there's your script.
 
Old 06-08-2010, 12:48 AM   #7
meandsushil
Member
 
Registered: Feb 2010
Posts: 143

Original Poster
Rep: Reputation: 14
how to make it executable? with .sh extension?
 
Old 06-08-2010, 12:59 AM   #8
kingston
Member
 
Registered: Mar 2008
Location: Bengaluru, India
Distribution: RHEL 5.5, Solaris 5.10
Posts: 193
Blog Entries: 1

Rep: Reputation: 21
set 777 as the permission.
 
Old 06-08-2010, 02:17 AM   #9
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,251

Rep: Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026
Actually, only the owner needs x perms, so use

chmod u+x script.sh

and ensure you supply the complete path to the script when calling it from cron.
 
Old 06-08-2010, 02:27 AM   #10
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Quote:
after every one minute
Why would you want to make a copy every minute?
As the contents of the 3 folders grow, the copy may take more than one minute to complete.

In other words, what are you really trying to accomplish with the copy?
A backup of all data on FTP (an incremental approach would be more efficient)?
 
Old 06-08-2010, 02:54 AM   #11
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 91
Quote:
In other words, what are you really trying to accomplish with the copy?
A backup of all data on FTP (an incremental approach would be more efficient)?
Agree with timmeke here - running the script every minute wastes resources. If you want to backup your FTP data another option (if you have another machine available) is to do an rsync of your FTP data between the FTP server and "Backup" Server.
 
Old 06-08-2010, 03:01 AM   #12
meandsushil
Member
 
Registered: Feb 2010
Posts: 143

Original Poster
Rep: Reputation: 14
so is this metthod?

vi script.sh
(insert)
cp -rf /home/ftp1
cp -rf /home/ftp1
cp -rf /home/ftp1
:wq!

chmod u+x script.sh

crontab -u root -e
(insert)
*/1 * * * * /root/script.sh
:wq!
 
Old 06-08-2010, 05:22 AM   #13
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Close, but you'll want to add the "target" location to the cp commands.
Maybe you can try the commands manually first too (even with -v for verbose prints)?

Why would you need to run this copy-script as root user?
This can add serious risks to system security (e.g. the copied files may be left with root as owner).

Last edited by timmeke; 06-08-2010 at 05:24 AM.
 
Old 06-08-2010, 06:29 AM   #14
Basse1
LQ Newbie
 
Registered: Jun 2010
Location: India
Posts: 14

Rep: Reputation: 1
Smile

Quote:
Originally Posted by meandsushil View Post
so is this metthod?

vi script.sh
(insert)
cp -rf /home/ftp1
cp -rf /home/ftp1
cp -rf /home/ftp1
:wq!

chmod u+x script.sh

crontab -u root -e
(insert)
*/1 * * * * /root/script.sh
:wq!



Here you go:


1)

vi script.sh
(insert)

#!/bin/bash
cp -rf /home/ftp1/* /ftpdata
cp -rf /home/ftp1/* /ftpdata
cp -rf /home/ftp1/* /ftpdata
wq!


2)

chmod +x script.sh

3)

crontab -u root -e
(insert)
*/1 * * * * /root/script.sh
:wq!
 
1 members found this post helpful.
Old 06-08-2010, 09:44 AM   #15
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,244

Rep: Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475
Quote:
Originally Posted by meandsushil View Post
how to make it executable? with .sh extension?
With the chmod command, same as you were told in another thread, where you asked about permissions....
 
1 members found this post helpful.
  


Reply

Tags
crontab


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
rsync -u Does it update the contents of a dir if that dir is changed? crazyivan Linux - Software 1 04-02-2008 03:08 AM
Recursive Delete DIR and Sub Dir with CONTENTS jCash Linux - Newbie 1 05-14-2007 05:54 PM
Can I prevent users from seeing dir contents? Jukas Linux - Newbie 5 04-08-2005 07:56 PM
d/l contents of a dir hfawzy Linux - General 2 05-08-2003 12:58 PM
auto rename contents of a DIR bkeating Linux - General 1 11-05-2002 06:34 PM


All times are GMT -5. The time now is 03:22 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration