スクリプト自体は次のようになります。
#!/bin/bash
file=/your_home_dir/temp_info
temperature=$(sensors | tail -3)
when=$(date "+%Y%m%d_%H%M%S")
working_proc=$(ps -aux | wc -l)
echo "$when num_proc: $working_proc" >> $file
echo "$temperature" >> $file
のような出力で
20130724_131150 num_proc: XXX
temp line1
temp line2
20130724_131250 num_proc: YYY
temp line1
temp line2
...
1分ごとに計算するには、次を使用できますcrontab
。
crontab -e
次の行を実行して追加します。
* * * * * /bin/sh /path/to/script.sh 2>/dev/null
crontab の詳細については、https: //stackoverflow.com/tags/crontab/info を参照してください。基本的な考え方:
- この式を使用する
* * * * *
と、crontab
は毎分、いつでも、いつでも実行されます。
- これにより
2>/dev/null
、架空のエラー メッセージがコンソールに表示されるのを回避できます。それらは「対象」で/dev/null
あるため、表示されません。アイデア: 実行ls -l /hellooooo
すると、エラー メッセージが表示されます。やれls -l /helloooo 2>/dev/null
ばやらない。