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?

link|improve this question
@akira: "So long as" is just as valid as "as long as" (also, why did you change it in the body of the question but not the title?). – Dennis Williamson May 26 '10 at 5:53
@dennis: didnt see it there. i ll roll it back. – akira May 26 '10 at 6:36
feedback

3 Answers

up vote 2 down vote accepted

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.

link|improve this answer
feedback

There is an option of rsync that limits I/O bandwidth:

--bwlimit=KBPS          limit I/O bandwidth; KBytes per second
link|improve this answer
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).

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.