#!/bin/sh set -eu usage() { cat <<-'EOF' Usage: nicely COMMAND... nicely -h EOF } help() { cat <<-'EOF' Options: -h, --help show this message COMMAND the command to be wrapped Wrap COMMAND in nice(1) and ionice(1) calls, so that it gets low priority from the OS scheduler and has low disturbance regarding CPU usage and disk IO bandwidth. Examples: Make the backup low priority: $ nicely backup EOF } for flag in "$@"; do case "$flag" in (--) break ;; (--help) usage help exit ;; (*) ;; esac done while getopts 'h' flag; do case "$flag" in (h) usage help exit ;; (*) usage >&2 exit 2 ;; esac done shift $((OPTIND - 1)) ionice -c3 nice -n19 "$@"