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
|