Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|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
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.

share|improve this answer

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

--bwlimit=KBPS          limit I/O bandwidth; KBytes per second
share|improve this answer

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):


for i in file1 file2 file3 etc

    LOAD=$(uptime | awk '{ sub(/,.*/, "", $9); print $9 * 100.0  }' )

    if [ $LOAD -lt 85 ]
        echo "copy $i to wherever"
        echo "sleep since load is $LOAD"
        sleep 5

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).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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