ノートPCがAC電源駆動中なのか、バッテリー駆動中なのかを確認するコマンドを紹介します。
今回紹介するon_ac_powerコマンドですが、CentOS6, Ubuntu12.04にあることと動作確認を行いました。
CentOS6とUbutnu12.04にインストールされているon_ac_powerのmanを確認しました。
違いは以下の通りで、電源が不明の場合のステータス記述がCentOS側には無いようです
NAME on_ac_power - test whether the computer is running on line power SYNOPSIS on_ac_power EXIT CODES The command succeeds (status 0) if the system is using line power and fails (status other than 0) otherwise. It is designed to be easy to use in shell scripts. 0 (true) System is on line power. 1 (false) System is not on line power.
NAME on_ac_power - test whether computer is running on AC power SYNOPSIS on_ac_power DESCRIPTION on_ac_power checks whether the system is running on AC power (i.e., mains power) as opposed to battery power. OPTIONS None. EXIT STATUS 0 (true) System is on mains power 1 (false) System is not on mains power 255 (false) Power status could not be determined
sakura@ubuntu:~$ on_ac_power sakura@ubuntu:~$ echo $? 0
sakura@ubuntu:~$ on_ac_power sakura@ubuntu:~$ echo $? 1
以上、ノートPCがAC電源駆動中なのかバッテリー駆動中なのかを確認する方法でした。