For reasons I won't get into, I need to copy directories so long as the average system load is low. Can someone help me write a BASH script that will copy the contents of a directory, but check to make sure the average system load is below X before copying each file, and if not, wait Y seconds and try again?
feedback
|
|
Can you just run rsync or whatever copy command you want to use combined with nice to set processor priority and/or ionice to set io priority. | |||
|
feedback
|
|
There is an option of --bwlimit=KBPS limit I/O bandwidth; KBytes per second | |||
|
feedback
|
|
just for the fun of it (and yes, i know that it does not try to copy the file again in case it went to sleep mode, i will leave that for your own amusement; walking over "$@" comes to mind + shifting):
#!/bin/bash
for i in file1 file2 file3 etc
do
LOAD=$(uptime | awk '{ sub(/,.*/, "", $9); print $9 * 100.0 }' )
if [ $LOAD -lt 85 ]
then
echo "copy $i to wherever"
else
echo "sleep since load is $LOAD"
sleep 5
fi
done
by using the load average of the last minute and only copying if the system is 85% idle, it will do something. anyway, i would just use rsync with throtteling (as dennis mentioned) plus set a high nice value (equals to low priority) to the rsync process (as zoredache mentioned) and let the os do the scheduling (which is designed to do just that). | |||
|
feedback
|