I needed a script to do this, so I wrote this:
#!/bin/bash -e # # Wait until there's less than -t of traffic in an interval of -i seconds. # fmt() { numfmt --to=si --suffix=B $1 } while getopts "i:m:" opt; do case $opt in i) interval=$OPTARG ;; t) minimum2=$(numfmt --from=si $OPTARG) ;; \?) echo "Invalid option: -$OPTARG" >&2 exit 1 ;; esac done shift $((OPTIND-1)) bytes=$(< /sys/class/net/eth1/statistics/rx_bytes ) minimum=-1 sleep $interval while [[ $(( $(< /sys/class/net/eth1/statistics/rx_bytes ) - $bytes )) -gt $minimum ]]; do minimum=$minimum2 rate=$(( $(< /sys/class/net/eth1/statistics/rx_bytes ) - $bytes )) echo $(date +%Y%m%d-%H%M%S)': received' $(fmt $rate) '('$(fmt $(( $rate / $interval )))'/s)' bytes=$(< /sys/class/net/eth1/statistics/rx_bytes ) sleep $interval done echo "End: received" $(fmt $(( $(< /sys/class/net/eth1/statistics/rx_bytes ) - $bytes ))) '('$(fmt $(( $rate / $interval )))'/s)'
Then use it like until-low-traffic -i 60 -m 1M && shutdown -h 1
or whatever.
(It could be made a lot simpler, if you fix the parameters and don't format the output.)