-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal_file_crontab.tf
More file actions
45 lines (39 loc) · 969 Bytes
/
local_file_crontab.tf
File metadata and controls
45 lines (39 loc) · 969 Bytes
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
resource "local_file" "crontab" {
content = <<EOF
#!/usr/bin/env bash
#
# This script ./bin/crontab.sh is used to install or clean crontab files
# gathered from different terraform modules in ./cron.d/ folder of the workspace
#
# Must be executed with sudo
# Usage: sudo ./bin/crontab.sh clean init
#
if [[ $UID != 0 ]]; then
echo "Please run this script with sudo:"
echo "sudo $0 $*"
exit 1
fi
[[ "$1" == "clean" ]] && {
ls -All /etc/cron.d/crontab_*
rm -rf /etc/cron.d/crontab_*
echo "CRONTAB REMOVED"
shift
}
[[ "$1" == "init" ]] && {
for i in ./cron.d/crontab_*; do
export fn=$(echo $i | cut -f3 -d/)
if [ -f /etc/cron.d/$fn ]; then
echo "$fn already installed"
else
cp -f $i /etc/cron.d/$fn
echo "$fn INSTALLED"
fi
chown root /etc/cron.d/$fn
chmod 0600 /etc/cron.d/$fn
done
echo "CRONTAB INSTALLED"
}
EOF
filename = "./bin/crontab.sh"
file_permission = "0777"
}