-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMac-Routine-Maintenance.sh
More file actions
65 lines (52 loc) · 1.82 KB
/
Mac-Routine-Maintenance.sh
File metadata and controls
65 lines (52 loc) · 1.82 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
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/zsh
# This script is provided AS IS without warranty of any kind.
# https://github.com/Mac-Nerd/Mac-scripts
# -----------------------------------------------------------
# This script will determine if it is necessary to run the Mac's built-in maintenance
# scripts. These normally run every day, week, and month - but sometimes are prevented
# or delayed. If the daily scripts haven't run in 2 days, the weekly in 8 days, or the
# monthly in 33 days, then the script triggers them automatically.
# Alternately, set the first command line parameter to "true" to force the maintenance
# routines to run immediately, regardless of when they were last run.
# For more detail about the periodic maintenance scripts, see:
# https://www.unix.com/man-page/mojave/8/PERIODIC/
forceRun="$1"
# if daily.out is older than 2 days
if [ -f "/var/log/daily.out" ]
then
dailyOutAge=$((($(date +%s) - $(stat -t %s -f %m -- "/var/log/daily.out")) / 86400))
else
dailyOutAge=99
fi
echo "Daily last run ${dailyOutAge} days ago."
# weekly.out older than 1 week
if [ -f "/var/log/weekly.out" ]
then
weeklyOutAge=$((($(date +%s) - $(stat -t %s -f %m -- "/var/log/weekly.out")) / 86400))
else
weeklyOutAge=99
fi
echo "Weekly last run ${weeklyOutAge} days ago."
# monthly.out older than 1m
if [ -f "/var/log/monthly.out" ]
then
monthlyOutAge=$((($(date +%s) - $(stat -t %s -f %m -- "/var/log/monthly.out")) / 86400))
else
monthlyOutAge=99
fi
echo "Monthly last run ${monthlyOutAge} days ago."
if [ $dailyOutAge -gt 2 ] || [[ "${forceRun:l}" == "true" ]]
then
echo "Running daily maintenance."
periodic daily
fi
if [ $weeklyOutAge -gt 8 ] || [[ "${forceRun:l}" == "true" ]]
then
echo "Running weekly maintenance."
periodic weekly
fi
if [ $monthlyOutAge -gt 33 ] || [[ "${forceRun:l}" == "true" ]]
then
echo "Running monthly maintenance."
periodic monthly
fi