]> arthur.barton.de Git - ppin.git/blob - contrib/ppinload.sh
Add some examle scripts
[ppin.git] / contrib / ppinload.sh
1 #!/bin/bash
2
3 [ -w /dev/ppin ] || exit 1
4 [ "$1" = "-v" ] && VERBOSE=1 || unset VERBOSE
5
6 export LC_ALL=C
7
8 function set_ppin_up_to()
9 {
10         declare -i count="$1"
11         declare -i n=0
12         while [ $n -lt 8 ]; do
13                 [ $n -lt $count ] \
14                         && echo "$n on" >/dev/ppin \
15                         || echo "$n off" >/dev/ppin
16         n=$n+1
17         done
18 }
19
20 function load_ppin()
21 {
22         if [ $load -lt 3 ]; then        #    < 0.03: 0 PINs     d=0.03
23                 set_ppin_up_to 0
24         elif [ $load -lt 10 ]; then     # 0.03-0.09: 1 PIN      d=0.07
25                 set_ppin_up_to 1
26         elif [ $load -lt 24 ]; then     # 0.10-0.24: 2 PIN      d=0.15
27                 set_ppin_up_to 2
28         elif [ $load -lt 50 ]; then     # 0.25-0.49: 3 PINs     d=0.25
29                 set_ppin_up_to 3
30         elif [ $load -lt 100 ]; then    # 0.50-0.99: 4 PINs     d=0.50
31                 set_ppin_up_to 4
32         elif [ $load -lt 200 ]; then    # 1.00-1.99: 5 PINs     d=1.00
33                 set_ppin_up_to 5 
34         elif [ $load -lt 400 ]; then    # 2.00-3.99: 6 PINs     d=2.00
35                 set_ppin_up_to 6
36         elif [ $load -lt 800 ]; then    # 4.00-7.99: 7 PINs     d=4.50
37                 set_ppin_up_to 7
38         else                            #    > 8.00: 8 PINs
39                 set_ppin_up_to 8
40         fi
41 }
42
43 while true; do
44         declare load_raw=`cat /proc/loadavg | cut -d' ' -f1`
45         declare -i load=`echo $load_raw | sed -e "s/\.//" | sed -e "s/^0*//g"`
46         [ -n "$VERBOSE" ] && echo "Load: $load_raw"
47         load_ppin
48         sleep 1
49 done