diff options
Diffstat (limited to 'dot_config/i3/scripts/executable_temperature')
-rw-r--r-- | dot_config/i3/scripts/executable_temperature | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/dot_config/i3/scripts/executable_temperature b/dot_config/i3/scripts/executable_temperature new file mode 100644 index 0000000..4e31610 --- /dev/null +++ b/dot_config/i3/scripts/executable_temperature | |||
@@ -0,0 +1,86 @@ | |||
1 | #!/usr/bin/env perl | ||
2 | # Copyright 2014 Pierre Mavro <[email protected]> | ||
3 | # Copyright 2014 Vivien Didelot <[email protected]> | ||
4 | # Copyright 2014 Andreas Guldstrand <[email protected]> | ||
5 | # Copyright 2014 Benjamin Chretien <chretien at lirmm dot fr> | ||
6 | |||
7 | # This program is free software: you can redistribute it and/or modify | ||
8 | # it under the terms of the GNU General Public License as published by | ||
9 | # the Free Software Foundation, either version 3 of the License, or | ||
10 | # (at your option) any later version. | ||
11 | |||
12 | # This program is distributed in the hope that it will be useful, | ||
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | # GNU General Public License for more details. | ||
16 | |||
17 | # You should have received a copy of the GNU General Public License | ||
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | # | ||
20 | # Edited by Andreas Lindlbauer <[email protected]> | ||
21 | |||
22 | use strict; | ||
23 | use warnings; | ||
24 | use utf8; | ||
25 | use Getopt::Long; | ||
26 | |||
27 | binmode(STDOUT, ":utf8"); | ||
28 | |||
29 | # default values | ||
30 | my $t_warn = $ENV{T_WARN} || 70; | ||
31 | my $t_crit = $ENV{T_CRIT} || 90; | ||
32 | my $chip = $ENV{SENSOR_CHIP} || ""; | ||
33 | my $temperature = -9999; | ||
34 | my $label = "😀 "; | ||
35 | |||
36 | sub help { | ||
37 | print "Usage: temperature [-w <warning>] [-c <critical>] [--chip <chip>]\n"; | ||
38 | print "-w <percent>: warning threshold to become yellow\n"; | ||
39 | print "-c <percent>: critical threshold to become red\n"; | ||
40 | print "--chip <chip>: sensor chip\n"; | ||
41 | exit 0; | ||
42 | } | ||
43 | |||
44 | GetOptions("help|h" => \&help, | ||
45 | "w=i" => \$t_warn, | ||
46 | "c=i" => \$t_crit, | ||
47 | "chip=s" => \$chip); | ||
48 | |||
49 | # Get chip temperature | ||
50 | open (SENSORS, "sensors -u $chip |") or die; | ||
51 | while (<SENSORS>) { | ||
52 | if (/^\s+temp1_input:\s+[\+]*([\-]*\d+\.\d)/) { | ||
53 | $temperature = $1; | ||
54 | last; | ||
55 | } | ||
56 | } | ||
57 | close(SENSORS); | ||
58 | |||
59 | $temperature eq -9999 and die 'Cannot find temperature'; | ||
60 | |||
61 | if ($temperature < 45) { | ||
62 | $label = 'ï‹‹'; | ||
63 | } elsif ($temperature < 55) { | ||
64 | $label = 'ï‹Š'; | ||
65 | } elsif ($temperature < 65) { | ||
66 | $label = ''; | ||
67 | } elsif ($temperature < 75) { | ||
68 | $label = ''; | ||
69 | } else { | ||
70 | $label = ''; | ||
71 | } | ||
72 | # Print short_text, full_text | ||
73 | print "${label}"; | ||
74 | print " $temperature°C\n"; | ||
75 | print "${label}"; | ||
76 | print " $temperature°C\n"; | ||
77 | |||
78 | # Print color, if needed | ||
79 | if ($temperature >= $t_crit) { | ||
80 | print "#FF0000\n"; | ||
81 | exit 33; | ||
82 | } elsif ($temperature >= $t_warn) { | ||
83 | print "#FFFC00\n"; | ||
84 | } | ||
85 | |||
86 | exit 0; | ||