File: failer

package info (click to toggle)
dar 2.8.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,024 kB
  • sloc: cpp: 86,219; sh: 6,978; ansic: 895; makefile: 489; python: 242; csh: 115; perl: 43; sed: 16
file content (34 lines) | stat: -rwxr-xr-x 709 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash

tmpfile=./tmp.failure.file

if [ -z "$1" ] ; then
    echo "usage: $0 <number>"
    echo ""
    echo "will create $tmpfile and store <number> in it, then fail."
    echo "If $tmpfile is already created the <number> in it"
    echo "will be decremented by one and $0 will fail again,"
    echo "up to the time the stored value reaches zero,"
    echo "at which time $tmpfile will be removed and $0"
    echo "will succeed"
    exit 1
fi

if [ ! -f "$tmpfile" ] ; then
    if [ $1 -gt 0 ] ; then
	echo $1 > "$tmpfile"
	exit 1
    else
	exit 0
    fi
else
    val=$(( `cat "$tmpfile"` - 1 ))
    if [ $val -gt 0 ] ; then
	echo $val > "$tmpfile"
	exit 1
    else
	rm -f "$tmpfile"
	exit 0
    fi
fi