std/c/: Delete the old Perl tests in src/t/, 0:84
[sunny256-utils.git] / randsleep
blob9222ef631a023b2a4c8f73a89adb95705bdbd01a
1 #!/usr/bin/env bash
3 #==============================================================================
4 # randsleep
5 # File ID: 23f387f0-7b1d-11ea-94a3-db5caa6d21d3
7 # Sleep for a random amount of time.
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #==============================================================================
13 progname=randsleep
14 VERSION=0.1.0
16 ARGS="$(getopt -o "\
20 " -l "\
21 help,\
22 quiet,\
23 verbose,\
24 version,\
25 " -n "$progname" -- "$@")"
26 test "$?" = "0" || exit 1
27 eval set -- "$ARGS"
29 opt_help=0
30 opt_quiet=0
31 opt_verbose=0
32 while :; do
33 case "$1" in
34 -h|--help) opt_help=1; shift ;;
35 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
36 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
37 --version) echo $progname $VERSION; exit 0 ;;
38 --) shift; break ;;
39 *) echo $progname: Internal error >&2; exit 1 ;;
40 esac
41 done
42 opt_verbose=$(($opt_verbose - $opt_quiet))
44 if test "$opt_help" = "1"; then
45 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
46 cat <<END
48 Sleep for a random amount of time.
50 Usage: $progname [options] [MIN_SECS [RANDOM_SECS]]
52 Sleep for MIN_SECS + RANDOM_SECS seconds. If no command line args are
53 specified, use 30 for both values.
55 Options:
57 -h, --help
58 Show this help.
59 -q, --quiet
60 Be more quiet. Can be repeated to increase silence.
61 -v, --verbose
62 Increase level of verbosity. Can be repeated. One -v displays a
63 status message with sleep time.
64 --version
65 Print version information.
67 END
68 exit 0
71 minsecs=30
72 randsecs=30
74 test -n "$1" && minsecs="$1"
75 test -n "$2" && randsecs="$2"
76 if echo "$minsecs$randsecs" | tr -d '[0-9]' | grep -q .; then
77 echo $progname: Arguments must be integer only >&2
78 exit 1
81 test $randsecs -eq 0 && randsecs=1
82 secs=$(($minsecs + $RANDOM % $randsecs))
83 test $opt_verbose -ge 1 && echo -n $(date +%H:%M:%S) sleep $secs...
84 sleep $secs
85 test $opt_verbose -ge 1 && echo done
87 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :