Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so dont bother with any of their useless mail servers here and just use oauth login instead. Thank the nice Russians for causing that. :)
Paste
Pasted as Bash by registered user uwe ( 13 years ago )
#!/bin/bash
# port to check
port=8200
# check every x seconds
checktime=15
# if check succeds, pause for x seconds (actually + checktime)
pausetime=285
# sabnzbd api/host
sab=1
sab_api='xxx'
sab_host='127.0.0.1:8080'
# blacklist = blacklisted programs, one per line
# folders = if one of the blacklisted programs has a file in $folders (one per line) open, it gets sigSTOPped.
base=/media/...
blacklist=$base/blacklist
folders=$base/folders
optlsof="-F p -a $((sed 's/^/-c "/;s/$/" /' "$blacklist"; sed 's/^/+D "/;s/$/" /' "$folders")| tr -d '\n')"
paused=0
while sleep "$checktime"; do
if lsof -Pni ":$port" -sTCP:ESTABLISHED; then
if [ $paused -eq 0 ]; then
if [ $sab -eq 1 ]; then
# sab pause
curl -s -o /dev/null "http://$sab_host/api?apikey=$sab_api&mode=pause"
fi
paused=1
fi
# kill -STOP everything else
pids="$(eval lsof $optlsof | tr -d p)"
kill -STOP $pids
# wait longer
sleep "$pausetime"
continue
fi
if [ $paused -eq 1 ]; then
if [ $sab -eq 1 ]; then
# sab resume
curl -s -o /dev/null "http://$sab_host/api?apikey=$sab_api&mode=resume"
fi
# kill -CONT everything else
pids="$(eval lsof $optlsof | tr -d p)"
kill -CONT $pids
paused=0
fi
done&
disown
Revise this Paste