timeopensuserebootsusesles

How can I know system boot time on SLES11 systems?


I am trying to calculate time taken by reboot on SUSE linux systems (SLES11 and SLES12 systems) as follows:

reboot_time = end_time - start_time

where
    start_time is "time at which reboot command is triggered"
    end_time   is "time at which system is ready after booting process, finishing up startup and userspace programs" OR "time when login is prompted soon after reboot"

I am able to know start_time. But not able to know time end_time for SLES11 systems (init.d SysV version). For SLES12 (systemd initialization), systemd-analyze was giving required information, but I am not able to figure out a reliable way for init.d systems. Is there any similar alternative on a SysV init system or SLES11 that could give me the time spent on booting (starting kernel, finish running startup programs and complete userspace initialization)?


Solution

  • You might get (non second precise) last shutdown date with the following command

    last -x | egrep "shutdown|reboot" | head -1 | awk '{print $5" "$7" "$6" "$8}'
    

    last -x can give you system boot / reboot & shutdown times, and all system boot logs since system creation. The problem is that is does not show years, and has only minute resolution.

    last reads various log binary log files (/var/log/wtmp utmp and btmp) You can use utmpdump utility to get shutdown & reboot timestamps with more precise timestamps

    utmpdump /var/log/wtmp | egrep "shutdown|reboot" | awk -F '[' '{print $9}' | sed 's/ ]//g'
    

    Ultimatively, you can get the elapsed time from shutdown to reboot with the following (horribly long) one liner:

    echo "System $(hostname) took $(($(date -d "$(LC_ALL=C utmpdump /var/log/wtmp 2>/dev/null| grep "reboot" | grep -Eo '[[:alpha:]]{3} [[:alpha:]]{3} [[:digit:]]{2} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2} [[:digit:]]{4}|[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}T[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}' | tail -1)" "+%s") - $(date -d "$(LC_ALL=C utmpdump /var/log/wtmp 2>/dev/null| grep "shutdown" | grep -Eo '[[:alpha:]]{3} [[:alpha:]]{3} [[:digit:]]{2} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2} [[:digit:]]{4}|[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}T[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}' | tail -1)" "+%s"))) to reboot"
    

    Explanation:

    You can also play with the output of utmpdump to retrieve login timestamps. Be aware that shutdown/reboot cycle is different from shutdown/system boot cycle, hence the commands have to be adapted to your usage. Also be aware that any forceful system resets will not be included in the logs, hence giving bogus values.