aboutsummaryrefslogtreecommitdiffstats
path: root/test.sh
blob: 8d9fe76ccee4593b3c339040e9c215c45a7e8850 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash
[ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -oe "$0" "$0" "$@"

LOCKDIR=/var/run/user/$UID/transcode_my_files

mkdir -p "${LOCKDIR}"

filename="${1}"
maxjobs=3
sleeptime=2
while true; do
    for i in $(seq $maxjobs); do
        lockfile="${LOCKDIR}/job_${i}"
        if ! test -e "${lockfile}"; then
            touch "${lockfile}" || exit 1
            sh -c "sleep 10; echo done:${filename}; rm '$lockfile'" &
            #flock -u "$0"
            exit 0
        fi
    done
    sleep $sleeptime
done