#!/bin/bash
# check every x seconds
checktime=10
# what to check, needs to have exit code 0 if sigSTOP should be issued
check="lsof -Pni :8200 -sTCP:ESTABLISHED"
# what pids to sigSTOP
pids="lsof -t -c par2 -c unrar -c python -c rtmpdump -c rsync"
# paused-file
pausef="/media/crypt/dl/run/paused"
# pid-file
pidf="/media/crypt/dl/run/sigstop.pid"
# main
paused=0
while sleep "$checktime"; do
if $check; then
$pids | xargs kill -STOP
paused=1
touch "$pausef"
continue
fi
if [ $paused -eq 1 ]; then
$pids | xargs kill -CONT
rm "$pausef"
paused=0
fi
done&
echo $! > "$pidf"
disown
Add a code snippet to your website: www.paste.org