-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMac-Check-Log-Size.sh
More file actions
82 lines (64 loc) · 2.09 KB
/
Mac-Check-Log-Size.sh
File metadata and controls
82 lines (64 loc) · 2.09 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# This script is provided AS IS without warranty of any kind.
# https://github.com/Mac-Nerd/Mac-scripts
# -----------------------------------------------------------
#
# When applications start having problems, often the first sign is that the error log
# for that application fills up with messages. This can also lead to slower performance
# overall, as the system is spending its time writing out errors to increasingly large
# log files. Ultimately, this will fill up the drive if left unchecked.
#
# To detect this situation, an easy check to run is the size of the log files on the
# machine. This script checks the log folders in each user's home directory, as well as
# the system, to determine if they are larger than an optional maximum parameter
# (default 500 Megs).
#
exitCode=1000
MaxLogSize=$1
if [ -z "$MaxLogSize" ]
then
MaxLogSize=500 # default max size 500M
fi
# list all Users' home directories (uses dscl in the rare instance they're not in /Users/*)
UserHomes=$(dscl /Local/Default -list /Users NFSHomeDirectory | awk '$2 ~ /^\/Users/ { print $2 }' )
for UserHome in ${UserHomes}
do
# Does the home folder have a Logs folder?
if [ -d "${UserHome}/Library/Logs" ]
then
logSizeMegs="$(du -mc ${UserHome}/Library/Logs | tail -1 | cut -f1)"
echo "\n[ ${UserHome} Logs ]: ${logSizeMegs} megabytes"
if [ $logSizeMegs -ne 0 ]
then
echo "Top items:"
du -h ${UserHome}/Library/Logs/* | sort -hr | head -10
if [ $logSizeMegs -gt $MaxLogSize ]
then
((exitCode++))
fi
fi
fi
done
syslogSizeMegs="$(du -mc /Library/Logs | tail -1 | cut -f1)"
echo "\n[ System Logs ]: ${syslogSizeMegs} megabytes"
if [ $syslogSizeMegs -ne 0 ]
then
echo "Top items:"
du -h /Library/Logs/* | sort -hr | head -10
if [ $syslogSizeMegs -gt $MaxLogSize ]
then
((exitCode++))
fi
fi
varlogSizeMegs="$(du -mc /var/log | tail -1 | cut -f1)"
echo "\n[ /var/log ]: ${varlogSizeMegs} megabytes"
if [ $varlogSizeMegs -ne 0 ]
then
echo "Top items:"
du -h /var/log/* | sort -hr | head -10
if [ $varlogSizeMegs -gt $MaxLogSize ]
then
((exitCode++))
fi
fi
exit "$exitCode"