brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: last -x shows whether a Linux server shut down cleanly or just went dark

Linux
~/tips/tip-linux-last-x-shutdown-reboot

last -x shutdown reboot | head

See the reboots and shutdowns of a machine, so you can tell a crash from a planned restart.

A server rebooted overnight and you want to know whether someone shut it down or it crashed. The login records that last reads also hold reboot and shutdown entries.

last -x shutdown reboot | head

-x adds system events to the list, such as shutdowns and runlevel changes. Naming shutdown and reboot limits the output to those two pseudo users. A clean restart shows a shutdown line right before a reboot line. A reboot line with no shutdown before it means the machine went down without saying goodbye: a power cut, a hard reset, a kernel panic or the watchdog.

For just the time of the current boot, who -b is quicker:

who -b

It prints a single line, system boot with the date and time.

I’d start with this before reading logs, because it tells you which kind of problem to look for. A missing shutdown sends you to the hardware and kernel logs of the previous boot; a clean shutdown sends you to whoever or whatever triggered it.

These commands read /var/log/wtmp. Newer distributions are moving away from that file because of the year 2038 problem, and some no longer write it at all, in which case last prints nothing useful. On those systems journalctl --list-boots shows the boots instead. The file can also be rotated, so very old entries may be gone.

Further reading: last(1) manual page, who(1) manual page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link