
これが初めて書いたBashのスクリプトになるなぁ、(しみじみ)
何だかやぼったい感じだけど・・・。ま、いいっしょ、使えれば。
でも、別に公開する程のものでもないなぁ。
使用方法
1)このスクリプトは、/proc/apmの中身を逐次読み出して、データファイル 'battery_history.dat'へ書き出すだけのプログラムです。
2)一方、このスクリプトは、常にフラッグファイル'batteryflag.txt'を参照します。そしてもし、このファイルの中身が'end'のみであれば、その時点で停止します。
3)したがって、このスクリプトを起動する前に、上記の名前のファイル2つを用意しておくのがよろしい。両者は空のテキストファイルで良いです。
4)起動したい時は、このスクリプトが'battery_check.sh'という名前だとしたら、
$ sh battery_check.sh &
と打ってみよう。
5)終了したい時はプロセスを直接切るか、'batteryflag.txt'の中身を'end'の文字のみにしてやってね。
#!/bin/sh
### This Program is to get the time-dependence of the battery.
### Output file is ./battery_history.dat as TEXT.
###
### How to use!
### Before running, you shuld note this use two files,
### 'battery_history.dat' and 'batteryflag.txt'.
### These files can be empty.
### This script will be running until you rewrite the text content of
### flag file 'batteryflag.txt' to an only word 'end'.
### The battery data will be added the file 'battery_history.dat',
### with the format , , ,
### and .
###
### Yas. Inamura
### Watch the battery data until flag word become to 'end'.
##echo "Now starting to watch the battery >> battery_history.dat"
Flag=`cat batteryflag.txt`
while [ "$Flag" != "end" ]; do
APM=`cat /proc/apm`
TMM=`cat /proc/uptime`
Remaining_battery_life=`echo ${APM}|awk '{print gensub(/\%/,"","G",$7)}'`
Battery_status=`echo ${APM}|awk '{print gensub(/0x/,"","G",$5)}'`
Now_Time_update=`echo ${TMM}|awk '{print $1}'`
case `echo ${APM}|awk '{print $4}'` in
'0x00')
Power_Sply=0
;;
'0x01')
Power_Sply=1
;;
esac
##echo "$Now_Time_update:$Remaining_battery_life"
echo "$Now_Time_update,$Remaining_battery_life,$Power_Sply,$Battery_status">>battery_history.dat
sleep 20
Flag=`cat batteryflag.txt`
done
Back to pre-page