-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassociateEvent
35 lines (27 loc) · 950 Bytes
/
associateEvent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
initLED() {
while true
do
if [ "$1" = "memory" ]; then
getPercentage=$(ps -eo %mem,comm | awk '{arr[$2]+=$1}; END {for (i in arr) {print i, arr[i]}}' | grep "$2")
elif [ "$1" = "cpu" ]; then
getPercentage=$(ps -eo %cpu,comm | awk '{arr[$2]+=$1}; END {for (i in arr) {print i, arr[i]}}' | grep "$2")
fi
getPercentage=$(awk '{print $2}' <<< "$getPercentage")
onTime=$(echo "$getPercentage/100" | bc -l)
offTime=$(echo "1-$onTime" | bc -l)
echo 1 | sudo tee /sys/class/leds/"$3"/brightness > /dev/null
sleep "$onTime"
echo 0 | sudo tee /sys/class/leds/"$3"/brightness > /dev/null
sleep "$offTime"
done
}
while getopts o:p:l: option; do
case $option in
o) opt=$OPTARG;;
p) prog=$OPTARG;;
l) led=$OPTARG;;
?) echo "Invalid option $OPTARG"
esac
done
initLED "$opt" "$prog" "$led"