Skip to content
Snippets Groups Projects

fix date time handling

Merged Hahn Axel (hahn) requested to merge 6683-parametrize-snmp_printer_wrapper into master
1 file
+ 14
5
Compare changes
  • Side-by-side
  • Inline
+ 14
5
@@ -85,15 +85,21 @@ lastLine=$( cat "$tmpfile" 2>/dev/null )
if [ -z "$lastLine" ]; then
ph.setStatus unknown
ph.status "Initializing ... storing last line of jorunallog ..."
journalctl -n 1 > "$tmpfile"
journalctl -n 1 | tail -1 > "$tmpfile"
else
ts=$( cut -f 1-3 -d " " <<< "$lastLine" )
# mydate is "Okt 12 16:23:36"
# mydate=$( cut -f 1-3 -d " " <<< "$lastLine" )
# what works:
# date -d "12 sec ago" +"%Y-%m-%d %H:%I:%S"
# date -d "Oct 12 14:24:04" +"%Y-%m-%d %H:%M:%S"
typeset -i iAge; iAge=$( ph.getFileAge "$tmpfile" )
# ts=$( date -d "${mydate}" +"%Y-%m-%d %H:%M:%S" )
ts=$( date -d "${iAge} sec ago" +"%Y-%m-%d %H:%M:%S" )
data=$( sudo journalctl --since "$ts" )
# for next run: insert last handled line
tail -1 <<< "$data" > "$tmpfile"
# detect last seen position and count lines from there
typeset -i iTotal; iTotal=$( wc -l <<< "$data" )
typeset -i iFrom; iFrom=$( grep -Fn "$lastLine" <<< "$data" | head -1 | cut -f 1 -d ':' )
@@ -121,6 +127,9 @@ else
echo "Limits: $sLimits"
echo "Raw data: Found $iLines new line(s) in the last $iAge sec"
# for next run: insert last handled line
test $iLines -gt 0 && tail -1 <<< "$data" > "$tmpfile"
fi
# cat "$tmpfile"
Loading