For finding a date in a log file I've arrived at the following crude command:
grep Updated /var/log/socklog/xbps/current | tail -n 1 | grep -Eo ^20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]
That does what I need, which is to output the date of the last system upgrade I did on my Void machine: for example 2019-01-24. But it's a pretty cumbersome line and quite crude as well. I assume there must be a more elegant solution to extract the needed date from this file. Incidentally, the date is comprised by the first 10 characters of the line containing the text
tail'd for (the last, or most recent, occurrence in the file). Any suggestions for a more elegant solution?
This line, btw, is being used to produce a
motd so that when I log into my system I'll see something like "last system upgrade 2019-01-24." So I created a script
/etc/motd.sh with that line in it, which then gets called from /etc/profile. Am I going about making the information visible in the correct way? What might be some other alternatives for doing what I want?
/etc/motd.sh looks like:
#!/bin/bash echo last system upgrade $(grep Updated /var/log/socklog/xbps/current | tail -n 1 | grep -Eo ^20[0-9][0-9]-[0-9][0-9]-[0-9][0-9])
PS Here's a sample line from the log file, as requested:
2019-01-15T18:05:51.31699 user.notice: Jan 15 12:05:51 xbps-install: Installed `brotli-1.0.7_1' successfully (rootdir: /). 2019-01-15T18:05:51.35465 user.notice: Jan 15 12:05:51 xbps-install: Updated `xwininfo-1.1.4_2' successfully (rootdir: /).