-
Notifications
You must be signed in to change notification settings - Fork 0
/
cekejdo
executable file
·68 lines (63 loc) · 1.96 KB
/
cekejdo
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
function print_help {
echo "Usage:"
echo " $(basename $0) [-h] [-i interval] <time>"
echo " -h ... print this help and exit"
echo " -i ... polling interval in seconds (default is 1)"
echo " -v ... be verbose (say what you are doing)"
echo " time ... time in following formats:"
echo " YYYY-MM-DDThh:mm"
echo " hh:mm"
echo " YYYY-MM-DD"
echo " zitraThh:mm"
}
# Parse arguments
INTERVAL=58
VERBOSE=""
while [[ $# -ne 0 ]]; do
case ${1} in
-h|--help)
print_help
exit 0
;;
-v|--verbose)
VERBOSE=1
;;
-i|--interval)
shift
INTERVAL="${1}"
;;
[0-9][0-9]:[0-9][0-9]*)
TIMESTAMP="$(echo $(date +%Y-%m-%d)T${1} | cut -c -16)"
;;
zitraT[0-9][0-9]:[0-9][0-9]*|tomorrowT[0-9][0-9]:[0-9][0-9]*)
TIMESTAMP="$(echo $(date +%Y-%m-%d -d tomorrow)T${1} | cut -c -16)"
TIMESTAMP=$(echo "${1}" | \
sed -e "s/zitra/"$(date +%Y-%m-%d -d tomorrow)"/g" \
-e "s/tomorrow/"$(date +%Y-%m-%d -d tomorrow)"/g" | \
cut -c -16)
;;
[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9])
TIMESTAMP="${1}T00:00"
;;
[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]*)
TIMESTAMP="$(echo ${1} | cut -c -16)"
;;
*)
echo "Invalid parameter ${1}"
exit 1
;;
esac
shift
done
[[ -z "${TIMESTAMP}" ]] && { echo "Missing valid timestamp"; exit 1; }
function kolikje () {
TZ='Europe/Prague' tedje=$(date -Iminutes | cut -d + -f 1)
[[ -n "${VERBOSE}" ]] && echo -e "Ted je: ${tedje}\nCekam na: ${TIMESTAMP}\n" 1>&2
echo "${tedje}"
return 0
}
while [[ "$(kolikje)" < "${TIMESTAMP}" ]]; do
sleep ${INTERVAL}
done
exit 0