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
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
06-07-2010, 12:43 AM
#1
Member
Registered: Feb 2010
Posts: 143
Rep:
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.
06-07-2010, 12:52 AM
#2
LQ Newbie
Registered: Jun 2010
Location: India
Posts: 14
Rep:
Quote:
Originally Posted by
meandsushil
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
06-07-2010, 01:34 AM
#3
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.2, Centos 5.8
Posts: 11,740
You require a regex to do it in one cmd eg
1 members found this post helpful.
06-07-2010, 02:38 AM
#4
Member
Registered: Feb 2010
Posts: 143
Original Poster
Rep:
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?
06-07-2010, 02:44 AM
#5
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.2, Centos 5.8
Posts: 11,740
06-07-2010, 12:26 PM
#6
Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 10,003
Quote:
Originally Posted by
meandsushil
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.
06-08-2010, 12:48 AM
#7
Member
Registered: Feb 2010
Posts: 143
Original Poster
Rep:
how to make it executable? with .sh extension?
06-08-2010, 12:59 AM
#8
Member
Registered: Mar 2008
Location: Bengaluru, India
Distribution: RHEL 5.5, Solaris 5.10
Posts: 170
Rep:
set 777 as the permission.
06-08-2010, 02:17 AM
#9
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.2, Centos 5.8
Posts: 11,740
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.
06-08-2010, 02:27 AM
#10
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515
Rep:
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)?
06-08-2010, 02:54 AM
#11
Member
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559
Rep:
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.
06-08-2010, 03:01 AM
#12
Member
Registered: Feb 2010
Posts: 143
Original Poster
Rep:
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!
06-08-2010, 05:22 AM
#13
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515
Rep:
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 .
06-08-2010, 06:29 AM
#14
LQ Newbie
Registered: Jun 2010
Location: India
Posts: 14
Rep:
Quote:
Originally Posted by
meandsushil
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.
06-08-2010, 09:44 AM
#15
Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 10,003
Quote:
Originally Posted by
meandsushil
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.
Thread Tools
Search 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
HTML code is Off
All times are GMT -5. The time now is 09:32 AM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News