![]() |
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. |
Quote:
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 |
You require a regex to do it in one cmd eg
Code:
cp dir[1-3] target |
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 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 |
Quote:
|
how to make it executable? with .sh extension?
|
set 777 as the permission.
|
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. |
Quote:
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)? |
Quote:
|
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! |
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). |
Quote:
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! |
Quote:
|
| All times are GMT -5. The time now is 06:11 PM. |