motd
motd copied to clipboard
grep treats portions of syslog as binary file
I noticed that sometimes grep aborts its search through syslog when it thinks portions of the file are binary. This resulted in missing the "Previous self test" lines that 36-diskststus needs.
To see the problem, I removed the second grep to get the results of the first grep with:
tac /var/log/syslog /var/log/syslog.1 | grep -hiP 'smartd\[[[:digit:]]+\]:'
It results in:

My solution is to use add --text to grep to force grep to treat the entire file as text. The diff is:
diff --git a/36-diskstatus b/36-diskstatus
index 43bbbe9..2bc43bd 100755
--- a/36-diskstatus
+++ b/36-diskstatus
@@ -23,7 +23,7 @@ hddtemp_port=7634
logfiles='/var/log/syslog /var/log/syslog.1'
# get all lines with smartd entries from syslog
-lines=$(tac $logfiles | grep -hiP 'smartd\[[[:digit:]]+\]:' | grep -iP "previous self-test")
+lines=$(tac $logfiles | grep --text -hiP 'smartd\[[[:digit:]]+\]:' | grep --text -iP "previous self-test")
# use nc to query temps from hddtemp daemon
hddtemp=$(timeout 0.01 nc $hddtemp_host $hddtemp_port | sed 's/|//m' | sed 's/||/ \n/g')