LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

on_ac_power

tests whether the system is running on AC power

TLDR

Check if on AC power
$ on_ac_power && echo "AC" || echo "Battery"
copy
Use in script conditionally
$ on_ac_power && backup.sh
copy
Check exit code
$ on_ac_power; echo $?
copy

SYNOPSIS

on_ac_power

DESCRIPTION

on_ac_power tests whether the system is running on AC (mains) power. It returns an exit code indicating power status.The tool is designed for scripting. Exit code 0 means AC power is connected. Exit code 1 means running on battery. Any other exit code indicates the power status cannot be determined.Common uses include scheduling heavy tasks only when plugged in, adjusting backup frequency based on power source, and power-aware cron jobs.The command checks various power subsystems including ACPI, APM, and sysfs to determine status. It works on laptops and systems with battery backup.On systems without batteries or power status information, the result may be unreliable.

EXIT CODES

0

System is on AC power.
1
System is on battery.
255
Cannot determine power status.

INSTALL

sudo apk add pm-utils
copy

CAVEATS

May not work on all systems. Desktop systems without UPS typically return "AC". Result depends on kernel power reporting. Some virtual machines report unknown.

HISTORY

on_ac_power is part of the powermgmt-base package on Debian-based systems. It provides a simple interface for power-aware scripting without parsing ACPI or sysfs directly.

SEE ALSO

acpi(1), upower(1), tlp(8), pm-utils(8)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid