Last active
November 9, 2024 03:53
-
-
Save tsibley/ba6ea4953da624c72821c3ed7425265b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# usage: clockins [<since>] | |
# | |
# <since> defaults to "yesterday". | |
set -euo pipefail | |
since="${1:-yesterday}${1:+ ago}" | |
{ | |
journalctl \ | |
--unit smartcard.target \ | |
--output json \ | |
--reverse \ | |
--since "$since" \ | |
JOB_TYPE={start,stop} \ | |
JOB_RESULT=done \ | |
| recs xform '{{__REALTIME_TIMESTAMP}} /= 1e6' \ | |
| recs collate -k INVOCATION_ID -a ts=vk,JOB_TYPE,__REALTIME_TIMESTAMP \ | |
| jq --raw-output ' | |
def parse_ts: | |
try { | |
date: strflocaltime("%Y-%m-%d"), | |
day: strflocaltime("%d %b"), | |
time: strflocaltime("%H:%M") | |
} | |
catch null | |
; | |
.start = (.ts.start | parse_ts) | |
| .stop = (.ts.stop | parse_ts) | |
| if .start and .stop then | |
if .start.date == .stop.date then | |
"\(.start.time)–\(.stop.time) \(.start.day)" | |
else | |
"\(.start.time)–\(.stop.time) \(.start.day)–\(.stop.day)" | |
end | |
elif .start then | |
"\(.start.time)– \(.start.day)" | |
elif .stop then | |
" –\(.stop.time) \(.stop.day)" | |
else | |
. # if here, then something weird is going on! | |
end | |
' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment