I configured a cronjob (running a bash script) with crontab -e which locally copies some data from one hard drive to another (rsync) and after that compares them (diff).

I executed the script manually to see if everything runs as planned. It copied 7 GB and took about 30 min. When it is started as cronjob it takes 4h, again copying 7 GB.

The data and script had not been changed since the manual call and the cronjob call of the script.

  • May it be that cronjobs run as daemons with very little priority?
  • If so, how can I change that?
  • I doubt that difference would be down to process priority. Could it be that the second time you ran it, there were more changes in the data so rsync had to copy more? How are you checking that both cases copied 7G? Did the manual and the automatic copy both use the exact same command and the exact same source and target directories? Are you copying across a network? – terdon Mar 10 '16 at 11:37
  • @terdon I edited my question! :) – Willi Mentzel Mar 10 '16 at 11:45

If my memory serves me well cron runs with a nice level 2.

Use nice. Example:

nice -20 {script} >>/dev/null 2>&1

(or a bit higher (-10, -15) if -20 is hogging your system too much). All "children" inside {script} will run with the same nice level as the "parent".

  • man page for nice.
  • There is also ionice for IO scheduling.
  • "Nicenesses" ranges from -20 (most favorable scheduling) to 19 (least favorable scheduling).
  • A process with a nice +15 will receive 25% of CPU time off a process with a nice +0 (that is (20 − 15)/(20 − 0) = 0.25).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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