From: akaketwa on 2 Sep 2006 04:12 I am stuck guys. may you help with how to program a linux shell script that copies files/folder from the local file system to another location on the local machine or a remote windows machine. additionally, this might need to be a cron task that runs once every week. thanx in advance!!
From: Andy on 2 Sep 2006 04:44 The following script when run will copy the contents of the source folder to the destination folder, if you are wanting to copy the files to a remote windows machine then you could share the folder on the windows system and then use 'samba' to mount the share on the unix machine? That way you could use a script as below to copy the files across? Andy. #!/bin/bash # cp -r /some/source/folder /some/destination/folder Don't forget to make the file executable before you try and run it using 'chmod 755 <filename>' ;-)
From: Akaketwa on 2 Sep 2006 05:25 thanks Andy. it works pretty fine. how then do you automate the task so that it runs as a scheduled task. may yu suggest ways of naming the folders that will be copied to the destination folder so that there wont be overwriting of stuff. thanks Andy wrote: > The following script when run will copy the contents of the source > folder to the destination folder, if you are wanting to copy the files > to a remote windows machine then you could share the folder on the > windows system and then use 'samba' to mount the share on the unix > machine? That way you could use a script as below to copy the files > across? > > Andy. > > > #!/bin/bash > # > cp -r /some/source/folder /some/destination/folder > > > Don't forget to make the file executable before you try and run it > using 'chmod 755 <filename>' ;-)
From: Andy on 2 Sep 2006 06:05 Hi, Try this :- #!/bin/bash # foldername=`date +%F-%H%M%S` cp -r /some/source/folder /some/destination/path/$foldername This will create a foldername in the format YYYY-MM-DD-hhmmss - you can change the format of the name by changing the parameters after the 'date' command. To automate this you can use cron. If you use crontab -e to edit the crontab. * * * * * command to be executed - - - - - | | | | | | | | | +----- day of week (0 - 6) (Sunday=0) | | | +------- month (1 - 12) | | +--------- day of month (1 - 31) | +----------- hour (0 - 23) +------------- min (0 - 59) As an example - 30 18 * * * rm /home/someuser/tmp/* A line in crontab file like below removes the tmp files from /home/someuser/tmp each day at 6:30 PM. Just replace the command in the example above with the /full/path/to/script to run you script when you like. The following link has a good description of cron with plenty of examples :- http://www.adminschoice.com/docs/crontab.htm
|
Pages: 1 Prev: Run a PL SQL Package from a shell script Next: "at" commond |