Advertisement
jackvasdeferens

i3 temperature script-FIXED to display °F

Nov 21st, 2017
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings;
  5. use utf8;
  6. use Getopt::Long;
  7.  
  8. binmode(STDOUT, ":utf8");
  9.  
  10. # default values
  11. my $t_warn = 70;
  12. my $t_crit = 90;
  13. my $chip = "";
  14. my $temperature = -9999;
  15.  
  16. sub help {
  17. print "Usage: temperature [-w <warning>] [-c <critical>] [--chip <chip>]\n";
  18. print "-w <percent>: warning threshold to become yellow\n";
  19. print "-c <percent>: critical threshold to become red\n";
  20. print "--chip <chip>: sensor chip\n";
  21. exit 0;
  22. }
  23.  
  24. GetOptions("help|h" => \&help,
  25. "w=i" => \$t_warn,
  26. "c=i" => \$t_crit,
  27. "chip=s" => \$chip);
  28.  
  29. # Get chip temperature
  30. open (SENSORS, "sensors -u $chip |") or die;
  31. while (<SENSORS>) {
  32. if (/^\s+temp1_input:\s+[\+]*([\-]*\d+\.\d)/) {
  33. $temperature = $1;
  34. last;
  35. }
  36. }
  37. close(SENSORS);
  38.  
  39. $temperature eq -9999 and die 'Cannot find temperature';
  40.  
  41. # Print short_text, full_text
  42. print "$temperature°C\n"*1.8+32;
  43.  
  44. # Print color, if needed
  45. if ($temperature >= $t_crit) {
  46. print "#FF0000\n";
  47. exit 33;
  48. } elsif ($temperature >= $t_warn) {
  49. print "#FFFC00\n";
  50. }
  51.  
  52. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement