The following shell script provides a solution to move the files from the /opt/a directory to /opt/b directory with 100 files/min which means it will only move 100 files from the /opt/a directory which can have thousands of file than have a delay of 1min and than again after 1min it will further move the 100 files till all the files in the directory /opt/a moves to other directory /opt/b
#!/bin/bash
#Find all the files only in directory /opt/a and count the number of the files, starttime will display when the script start executing
count=`find /opt/a/ -type f | wc -l`
starttime=`date`
echo "The script started at $starttime"
#The condition is set till the file count is greater than 0 continue moving files and reduce the counter by 100
#A delay is introduce by sleep command
while [ $count -gt 0 ]
do
find /opt/a/ -type f | head -100 | xargs mv -t /opt/b/
/bin/sleep 60
((count= $count - 100))
done
echo "The script completed at `date`"
exit 0
The practical application of this script can be configured if you don't want to increase the throughput on the server. Also it will keep a check on the network resources in case files are larger in size.
0 comments:
Post a Comment