このエントリーをはてなブックマークに追加


AC電源駆動かバッテリー駆動なのかを確認する方法

ノートPCがAC電源駆動中なのか、バッテリー駆動中なのかを確認するコマンドを紹介します。
今回紹介するon_ac_powerコマンドですが、CentOS6, Ubuntu12.04にあることと動作確認を行いました。


on_ac_powerコマンド

CentOS6とUbutnu12.04にインストールされているon_ac_powerのmanを確認しました。
違いは以下の通りで、電源が不明の場合のステータス記述がCentOS側には無いようです

  • 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.
  • Ubuntu
    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

実際にon_ac_powerを使ってみる

  • AC電源の時
    sakura@ubuntu:~$ on_ac_power
    sakura@ubuntu:~$ echo $?
    0
  • バッテリー駆動の時
    sakura@ubuntu:~$ on_ac_power
    sakura@ubuntu:~$ echo $?
    1

以上、ノートPCがAC電源駆動中なのかバッテリー駆動中なのかを確認する方法でした。



トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2015-03-20 (金) 22:28:31