I want to know how long the system will last on a full battery.Why do you care so much about uptime? The datetime stamps in /var/log/messages will tell you when the system started shutting down, assuming it does a 'proper' shutdown, not an instant off kind of thing.
Does dmesg record the time of a shutdown when a system shuts down when it runs out of power?It's easy enough to figure out when the system booted (that's in the log), and when it shut down. Either the shutdown is in the log, or regular log updates from other subsystems stop happening. Then calculate the difference yourself.
Not quite what you're after but does report number of startups/shut downs, system life etcsysutils/tuptime
> tuptime
System startups: 111 since 15:22:20 28/06/2025
System shutdowns: 98 ok + 12 bad
System life: 354d 4h 11m 44s
Longest uptime: 14d 12h 7m 38s from 22:34:36 16/09/2025
Average uptime: 1d 22h 24m 54s
System uptime: 60.61% = 214d 16h 4m 34s
Longest downtime: 42d 5h 21m 34s from 12:13:32 14/02/2026
Average downtime: 1d 6h 26m 15s
System downtime: 39.39% = 139d 12h 7m 10s
Current uptime: 9h 40m 42s since 09:53:22 17/06/2026
Never heard of tuptime before but thanks for drawing my attention to it.Not quite what you're after but does report number of startups/shut downs, system life etc
If the system shuts down, the shutdown will be recorded in /var/log/messages.Does dmesg record the time of a shutdown when a system shuts down when it runs out of power?
kernel: battery0: critically low charge!If the system shuts down, the shutdown will be recorded in /var/log/messages.
If the battery is set up correctly, the system should go through shutdown before the battery runs out.
If the system just stops, dmesg and /var/log/messages can't record that. But you get a pretty accurate idea of when it happens by looking at other log entries: What was the last message before the reboot?
Won't that depend on the load you put on the battery? Or are you just going to leave it idle to see the "best" it can do with no load? Just curious, not being snarky.I want to know how long the system will last on a full battery.
#!/bin/sh
# Path to the output file (change this to your preferred path)
TARGET_FILE="date_log.txt"
# Ensure the file exists before writing to it
touch "$TARGET_FILE"
echo "Starting date logger. Writing to $TARGET_FILE every 2 minutes..."
while true; do
# Append the current date and time to the file
date >> "$TARGET_FILE"
# Force flushing of the file's in-core state to the disk
fsync "$TARGET_FILE"
# Pause for 120 seconds (2 minutes)
sleep 120
done
nohup ./sync_date.sh > /dev/null 2>&1 &