Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as Bash by registered user uwe ( 11 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

Your Name: Code Language: