Linux command
on_ac_power 命令
文本
涉及管道、覆盖或删除,执行前请先确认路径和参数。
常用示例
Check if on AC power
on_ac_power && echo "AC" || echo "Battery"
Use in script conditionally
on_ac_power && backup.sh
Check exit code
on_ac_power; echo $?
说明
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.
FAQ
What is the on_ac_power command used for?
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.
How do I run a basic on_ac_power example?
Run `on_ac_power && echo "AC" || echo "Battery"` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
Where can I find more on_ac_power examples?
This page includes 3 examples for on_ac_power, plus related commands for nearby Linux tasks.