-
Notifications
You must be signed in to change notification settings - Fork 0
/
2004simple-uptime-log.sh
executable file
·47 lines (38 loc) · 1.16 KB
/
2004simple-uptime-log.sh
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
#!/usr/bin/env bash
# Sometimes you need evidence to prove
# that at computer turns on and shuts down as programmed.
# This script once pr. hour writes a timestamp to a textfile.
# This of course only happens when the computer is awake,
# thereby creating evidence of uptime and downtime.
logging_script="/etc/cron.hourly/simpleuptimelog"
cleanup_script="/etc/cron.monthly/cleanupsimpleuptimelog"
logfile="/home/superuser/simpleuptimelog.txt"
if [ "$1" == "disable" ]
then
echo "Removing cron scripts and log-file."
rm -f $logging_script
rm -f $cleanup_script
rm -f $logfile
echo "Done."
exit 0
elif [ "$1" == "enable" ]
then
echo "Writing logging-script to cron.hourly."
# Every hour add timestamp to a log-file
rm -f $logging_script
cat <<'EOF' >> $logging_script
#!/bin/bash
echo $(date +%Y-%m-%d_%H:%M) >> /home/superuser/simpleuptimelog.txt
EOF
chmod +x $logging_script
echo "Writing cleanup-script to cron.monthly."
# Once a month empty the log-file
rm -f $cleanup_script
cat <<'EOF' >> $cleanup_script
#!/bin/bash
> /home/superuser/simpleuptimelog.txt
EOF
chmod +x $cleanup_script
echo "Done."
exit 0
fi