Pastebin

Paste #1772: zsh daemon

< previous paste - next paste>

Pasted by tdn

Download View as text

function daemon() {
    name=$1
    delay=$2
    cmd=$3
    lockfile="/tmp/$name.lck"
    pidfile="/tmp/$name.pid"
    touch $lockfile
    (
        while sleep $delay && [[ -f $lockfile ]]; do
            eval $cmd
        done
        echo "Stopping $name"
    )&
    pid=$!
    echo $pid > $pidfile
    echo "Started $name with PID: $pid"
}

New Paste


Do not write anything in this field if you're a human.

Go to most recent paste.