LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to copy 3 dir's contents to 1 dir by crontab? (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-copy-3-dirs-contents-to-1-dir-by-crontab-812595/)

meandsushil 06-07-2010 12:43 AM

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.


Basse1 06-07-2010 12:52 AM

Quote:

Originally Posted by meandsushil (Post 3994981)
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

chrism01 06-07-2010 01:34 AM

You require a regex to do it in one cmd eg

Code:

cp dir[1-3] target

meandsushil 06-07-2010 02:38 AM

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?

chrism01 06-07-2010 02:44 AM

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

TB0ne 06-07-2010 12:26 PM

Quote:

Originally Posted by meandsushil (Post 3995057)
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.

meandsushil 06-08-2010 12:48 AM

how to make it executable? with .sh extension?

kingston 06-08-2010 12:59 AM

set 777 as the permission.

chrism01 06-08-2010 02:17 AM

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.

timmeke 06-08-2010 02:27 AM

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)?

alli_yas 06-08-2010 02:54 AM

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.

meandsushil 06-08-2010 03:01 AM

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!

timmeke 06-08-2010 05:22 AM

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).

Basse1 06-08-2010 06:29 AM

Quote:

Originally Posted by meandsushil (Post 3996318)
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!

TB0ne 06-08-2010 09:44 AM

Quote:

Originally Posted by meandsushil (Post 3996189)
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....


All times are GMT -5. The time now is 09:54 PM.