Skip to content
Snippets Groups Projects
Commit bb2aff31 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch '6683-parametrize-snmp_printer_wrapper' into 'master'

fix date time handling

See merge request !187
parents 373436cb 3e88dade
No related branches found
No related tags found
1 merge request!187fix date time handling
...@@ -85,15 +85,21 @@ lastLine=$( cat "$tmpfile" 2>/dev/null ) ...@@ -85,15 +85,21 @@ lastLine=$( cat "$tmpfile" 2>/dev/null )
if [ -z "$lastLine" ]; then if [ -z "$lastLine" ]; then
ph.setStatus unknown ph.setStatus unknown
ph.status "Initializing ... storing last line of jorunallog ..." ph.status "Initializing ... storing last line of jorunallog ..."
journalctl -n 1 > "$tmpfile" journalctl -n 1 | tail -1 > "$tmpfile"
else 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" ) 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" ) 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 # detect last seen position and count lines from there
typeset -i iTotal; iTotal=$( wc -l <<< "$data" ) typeset -i iTotal; iTotal=$( wc -l <<< "$data" )
typeset -i iFrom; iFrom=$( grep -Fn "$lastLine" <<< "$data" | head -1 | cut -f 1 -d ':' ) typeset -i iFrom; iFrom=$( grep -Fn "$lastLine" <<< "$data" | head -1 | cut -f 1 -d ':' )
...@@ -121,6 +127,9 @@ else ...@@ -121,6 +127,9 @@ else
echo "Limits: $sLimits" echo "Limits: $sLimits"
echo "Raw data: Found $iLines new line(s) in the last $iAge sec" 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 fi
# cat "$tmpfile" # cat "$tmpfile"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment