-
Notifications
You must be signed in to change notification settings - Fork 30
/
start-cron
executable file
·40 lines (35 loc) · 941 Bytes
/
start-cron
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
#!/usr/bin/env bash
# setting user for additional cron jobs
case $1 in
-u=*|--user=*)
crontab_user="-u ${1#*=}"
shift
;;
-u|--user)
crontab_user="-u $2"
shift 2
;;
-*)
echo "Unknown option: ${1%=*}" > /dev/stderr
exit 1
;;
*)
crontab_user=""
;;
esac
# adding additional cron jobs passed by arguments
# every job must be a single quoted string and have standard crontab format,
# e.g.: start-cron --user user "0 \* \* \* \* env >> /var/log/cron.log 2>&1"
{ for cron_job in "$@"; do echo -e ${cron_job}; done } \
| sed --regexp-extended 's/\\(.)/\1/g' \
| crontab ${crontab_user} -
# start cron
default_crontabs_dir=/etc/crontabs
crond -L /var/log/cron.log -c ${CRONTABS_DIR:-$default_crontabs_dir}
# trap SIGINT and SIGTERM signals and gracefully exit
trap "echo \"stopping cron\"; kill \$!; exit" SIGINT SIGTERM
# start "daemon"
while true
do
cat /var/log/cron.log & wait $!
done