-
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy path102-cron.sh
More file actions
executable file
·53 lines (41 loc) · 1.2 KB
/
102-cron.sh
File metadata and controls
executable file
·53 lines (41 loc) · 1.2 KB
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
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
###########################################################
# Functions
############################################################
# add line to devilbox's crontab, if not already there
# and start cron service
cron_add() {
# save the entire line in one variable
line="$*"
DEBUG_LEVEL="$( env_get "DEBUG_ENTRYPOINT" "0" )"
# check if line already exists in crontab
crontab -l -u devilbox | grep "$line" > /dev/null
status=$?
if [ $status -ne 0 ]
then
log "info" "cron: adding line '${line}' ..." "$DEBUG_LEVEL"
(crontab -l -u devilbox; echo "$line";) | crontab -u devilbox -
fi
# make sure the cron service is running
if ! service cron status >/dev/null
then
service cron start
fi
}
export -f cron_add
cron_remove() {
# save the entire line in one variable
line=$*
DEBUG_LEVEL="$( env_get "DEBUG_ENTRYPOINT" "0" )"
# check if line already exists in crontab
crontab -l -u devilbox | grep "$line" > /dev/null
status=$?
if [ $status -eq 0 ]; then
log "info" "cron: removing line '${line}' ..." "$DEBUG_LEVEL"
(crontab -l -u devilbox | grep -v "$line";) | crontab -u devilbox -
fi
}
export -f cron_remove