Before you begin
- Bash 4+ on Linux.
- Required tools: last. Minimal distributions may not retain wtmp history.
Set up your example
- Save as linux-reboot-history.sh.
- Open a terminal in its folder.
- Run bash "linux-reboot-history.sh" --help; invoking bash does not require executable permission.
This recipe uses your own local input or creates its own example output. Follow the setup steps below.
Download the ZIP, extract it, and open a terminal inside the extracted folder. The source file is linux-reboot-history.sh.
Run the script
bash "linux-reboot-history.sh" 10If your system uses python3 instead of python, use that command for Python examples. Keep paths containing spaces in quotes. Required inputs and optional settings are described in the code and setup steps.
What to expect
Up to ten boot and shutdown records appear.
The complete script
#!/usr/bin/env bash
set -euo pipefail
if [[ ${1:-} == --help || ${1:-} == -h ]]; then
cat <<\SCRIPTAGE_HELP
Review boot and shutdown history
Usage: bash linux-reboot-history.sh [COUNT]
Display a bounded list of reboot and shutdown records from wtmp.
Read-only local report.
SCRIPTAGE_HELP
exit 0
fi
for tool in last; do
command -v "$tool" >/dev/null 2>&1 || { printf 'Missing required tool: %s\n' "$tool" >&2; exit 1; }
done
count=${1:-10}
[[ "$count" =~ ^[0-9]+$ ]] && (( count >= 1 && count <= 100 )) || { printf 'Count must be 1..100\n' >&2; exit 1; }
last -x -n "$count" reboot shutdown
Open source as plain text · Download source and sample files
How it works
- Display a bounded list of reboot and shutdown records from wtmp.
- Required commands are checked before collecting the report.
- The output is a local snapshot; restricted permissions or unavailable kernel data can limit visibility.
Make it your own
Adjust scope
Set COUNT from 1 to 100; retained history depends on local wtmp policy.
Save a snapshot
Redirect to a new unused .txt filename for comparison. Shell redirection can overwrite files; choose a fresh name.
Change one setting at a time, run it again on sample data, and compare the output. The customization guide walks through this process.
If something goes wrong
A required tool is missing.
Install its package through your normal distribution maintenance process. This script does not install anything.
The report is empty or permission is denied.
Minimal distributions may not retain wtmp history.
Reference & next steps
These official references explain the underlying tools. The Scriptage example and guide are original instructional content. See verification notes for what has been checked and the limits of those checks.
Copies a template for your own notes. It does not send anything.