Maverickcdn
Senior Member
Until the day Asus or RMerlin add a WAN up date/time value in nvram or tmp file Ive been working on a way to try and calc WAN uptime from log messages (ie wan-event connected, wan: finish adding multi routes, Initial clock set messages)
Wondering what would be the best message in the logs to search for to detect boot/reboot (pre NTP sync) date/time.
I know about the boot date in rc '#define RC_BUILDTIME 1525496688 // May 5 05:04:48 GMT 2018' but depending on configured TZ this can change (ie. My boot date/time is May 4 @23:05 MDT -6 as first messages after klogd is started)
Its either searching the logs for currently "Linux version" and pulling the date/time, or should I write a function to pull TZ from nvram and calculate from RC_BUILDTIME what date/timeklogd all syslog messages would be pre NTP sync?
First 10 lines from my AC86 boot seq.
This is necessary to filter search results that are from boot/reboot not a true WAN up/down event. Whatever route it is, it needs to work across all models from FW 384.15+
Anyone got any ideas?
Wondering what would be the best message in the logs to search for to detect boot/reboot (pre NTP sync) date/time.
I know about the boot date in rc '#define RC_BUILDTIME 1525496688 // May 5 05:04:48 GMT 2018' but depending on configured TZ this can change (ie. My boot date/time is May 4 @23:05 MDT -6 as first messages after klogd is started)
Its either searching the logs for currently "Linux version" and pulling the date/time, or should I write a function to pull TZ from nvram and calculate from RC_BUILDTIME what date/time
First 10 lines from my AC86 boot seq.
Code:
MavMAIN|>/jffs/scripts| cat /tmp/syslog.log-1 | grep 'May 4' | head -n 10
May 4 23:05:05 syslogd started: BusyBox v1.25.1
May 4 23:05:05 syslogd: using server 10.1.1.11:514
May 4 23:05:05 kernel: klogd started: BusyBox v1.25.1 (2022-03-25 10:24:27 EDT)
May 4 23:05:05 kernel: Booting Linux on physical CPU 0x0
May 4 23:05:05 kernel: Linux version 4.1.27 (merlin@ubuntu-dev) (gcc version 5.3.0 (Buildroot 2016.02) ) #2 SMP PREEMPT Fri Mar 25 11:09:05 EDT 2022
May 4 23:05:05 kernel: CPU: AArch64 Processor [420f1000] revision 0
May 4 23:05:05 kernel: Detected VIPT I-cache on CPU0
May 4 23:05:05 kernel: alternatives: enabling workaround for ARM erratum 845719
May 4 23:05:05 kernel: On node 0 totalpages: 123904
May 4 23:05:05 kernel: DMA zone: 1792 pages used for memmap
Code:
# Try to detect default boot date/time as differs based on set timezone
boot_string='Linux version'
F_boot_date() {
fnd_boot=$(grep "$boot_string" /tmp/syslog.log-1 2>/dev/null | head -n1)
[ -z "$fnd_boot" ] && fnd_boot=$(grep "$boot_string" /tmp/syslog.log 2>/dev/null | head -n1)
[ -z "$fnd_boot" ] && logger -st "wanuptime[$$]" "ERROR - could not detect router boot date" && F_printf "Couldn't locate $boot_string ,did you reset logs?"
boot_mth=$(echo "$fnd_boot" | awk '{print $1}') ;boot_day=$(echo "$fnd_boot" | awk '{print $2}')
boot_hr=$(echo "$fnd_boot" | awk '{print $3}' | cut -d':' -f1) ;boot_min=$(echo "$fnd_boot" | awk '{print $3}' | cut -d':' -f2)
[ "$boot_min" -ne 0 ] && boot_low=$((boot_min - 1)) ;boot_high=$((boot_min + 5)) # 6 minute window incase NTP takes long to sync
}
This is necessary to filter search results that are from boot/reboot not a true WAN up/down event. Whatever route it is, it needs to work across all models from FW 384.15+
Anyone got any ideas?
Last edited: