Lines 1-5
Link Here
|
1 |
#!/bin/sh |
1 |
#!/bin/sh |
2 |
|
2 |
|
|
|
3 |
ACPI=/usr/bin/acpi |
4 |
IOSTAT=/usr/bin/iostat |
5 |
|
3 |
print_date() { |
6 |
print_date() { |
4 |
# The date is printed to the status bar by default. |
7 |
# The date is printed to the status bar by default. |
5 |
# To print the date through this script, set clock_enabled to 0 |
8 |
# To print the date through this script, set clock_enabled to 0 |
Lines 10-90
Link Here
|
10 |
} |
13 |
} |
11 |
|
14 |
|
12 |
_print_cpu() { |
15 |
_print_cpu() { |
13 |
typeset -R4 _1=${1} _2=${2} _3=${3} _4=${4} _5=${5} |
16 |
echo -n "CPU: ${1}% User ${2}% Nice ${3}% Sys ${6}% Idle " |
14 |
echo -n "CPU:${_1}% User${_2}% Nice${_3}% Sys${_4}% Int${_5}% Idle " |
|
|
15 |
} |
17 |
} |
16 |
|
18 |
|
17 |
print_cpu() { |
19 |
print_cpu() { |
18 |
OUT="" |
20 |
OUT="" |
19 |
# iostat prints each column justified to 3 chars, so if one counter |
21 |
# Remove the decimal part from all the percentages |
20 |
# is 100, it jams up agains the preceeding one. sort this out. |
|
|
21 |
while [ "${1}x" != "x" ]; do |
22 |
while [ "${1}x" != "x" ]; do |
22 |
if [ ${1} -gt 99 ]; then |
23 |
OUT="$OUT `echo $1 | cut -d '.' -f 1`" |
23 |
OUT="$OUT ${1%100} 100" |
24 |
shift |
24 |
else |
|
|
25 |
OUT="$OUT ${1}" |
26 |
fi |
27 |
shift; |
28 |
done |
25 |
done |
29 |
_print_cpu $OUT |
26 |
_print_cpu $OUT |
30 |
} |
27 |
} |
31 |
|
28 |
|
32 |
print_apm() { |
29 |
print_acpi() { |
33 |
BAT_STATUS=$1 |
30 |
BAT_STATUS=$3 |
34 |
BAT_LEVEL=$2 |
31 |
BAT_LEVEL=`echo $4 | tr -d ','` |
35 |
AC_STATUS=$3 |
32 |
|
36 |
|
33 |
case $BAT_STATUS in |
37 |
if [ $AC_STATUS -ne 255 -o $BAT_STATUS -lt 4 ]; then |
34 |
"Charging,") |
38 |
if [ $AC_STATUS -eq 0 ]; then |
35 |
FULL="on AC: (battery ${BAT_LEVEL})" |
39 |
echo -n "on battery (${BAT_LEVEL}%)" |
36 |
;; |
40 |
else |
37 |
"Discharging,") |
41 |
case $AC_STATUS in |
38 |
FULL="on battery (${BAT_LEVEL})" |
42 |
1) |
39 |
;; |
43 |
AC_STRING="on AC: " |
40 |
"") |
44 |
;; |
41 |
FULL="on AC (no battery)" |
45 |
2) |
42 |
;; |
46 |
AC_STRING="on backup AC: " |
43 |
*) |
47 |
;; |
44 |
FULL="(battery unknown)" |
48 |
*) |
45 |
;; |
49 |
AC_STRING="" |
46 |
esac; |
50 |
;; |
47 |
|
51 |
esac; |
48 |
echo -n "$FULL" |
52 |
case $BAT_STATUS in |
|
|
53 |
4) |
54 |
BAT_STRING="(no battery)" |
55 |
;; |
56 |
[0-3]) |
57 |
BAT_STRING="(battery ${BAT_LEVEL}%)" |
58 |
;; |
59 |
*) |
60 |
BAT_STRING="(battery unknown)" |
61 |
;; |
62 |
esac; |
63 |
|
64 |
FULL="${AC_STRING}${BAT_STRING}" |
65 |
if [ "$FULL" != "" ]; then |
66 |
echo -n "$FULL" |
67 |
fi |
68 |
fi |
69 |
fi |
70 |
} |
49 |
} |
71 |
|
50 |
|
72 |
while :; do |
51 |
# instead of sleeping, use iostat as the update timer. |
73 |
# instead of sleeping, use iostat as the update timer. |
52 |
# cache the output of acpi(1), no need to call that every second. |
74 |
# cache the output of apm(8), no need to call that every second. |
53 |
ACPI_DATA="" |
75 |
/usr/sbin/iostat -C -c 3600 |& # wish infinity was an option |
54 |
I=0 |
76 |
APM_DATA="" |
55 |
$IOSTAT -c 3 2>&1 | |
77 |
I=0 |
56 |
while read IOSTAT_DATA; do |
78 |
while read -p; do |
57 |
if [ $(( ${I} % 10 )) -eq 0 ]; then |
79 |
if [ $(( ${I} % 1 )) -eq 0 ]; then |
58 |
ACPI_DATA=`$ACPI -b` |
80 |
APM_DATA=`/usr/sbin/apm -alb` |
59 |
fi |
81 |
fi |
60 |
if [ $(( ${I} % 3 )) -eq 0 ] && [ $I -gt 2 ]; then |
82 |
if [ $I -gt 2 ]; then |
61 |
# print_date |
83 |
# print_date |
62 |
print_cpu $IOSTAT_DATA |
84 |
print_cpu $REPLY |
63 |
print_acpi $ACPI_DATA |
85 |
print_apm $APM_DATA |
64 |
echo "" |
86 |
echo "" |
65 |
fi |
87 |
fi |
66 |
I=$(( ${I} + 1 )); |
88 |
I=$(( ${I} + 1 )); |
|
|
89 |
done |
90 |
done |
67 |
done |