on_ac_power (1) - Linux Manuals
on_ac_power: test whether computer is running on AC power
on_ac_power - test whether computer is running on AC power
DESCRIPTIONon_ac_power checks whether the system is running on abundant power (such as AC mains, an USB charger, etc), as opposed to battery power.
0 (true) System is on mains power 1 (false) System is not on mains power 255 (false) Power status could not be determined
CAVEATSThe vast majority of desktops and servers have no power sensors, thus they return 255 "unknown"; for most purposes you'd want to consider this answer to imply mains power --- note that 255 evaluates as false for the shell.
AUTHORThis manual page was written by Steve Dodd <steved [at] loth.demon.co.uk>, was updated by Thomas Hood then by Adam Borowski.