Created
December 27, 2019 04:25
-
-
Save ablakely/a17ab2ddfe664bae61c814895e7e01b8 to your computer and use it in GitHub Desktop.
i3status lm-sensor script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# cpu temp/fan speed script for i3status | |
# | |
# Hardware: Lenovo ThinkPad w520 | |
# Written by Aaron Blakely <[email protected]> | |
# Date: 12/24/2019 | |
# Version: v1.0 | |
# | |
# Dependencies: lm-sensors | |
# | |
# Note: Only works with w520 or similar quad core systems? | |
# might add more later | |
use strict; | |
use warnings; | |
# USE Farenhiet | |
# Set to 1 for true | |
my $USEF = 1; | |
# OUTPUT String: | |
# This is where you format the output of the script: | |
# | |
my $OUT = "[TEMP] CPU: 0: !core0! 1: !core1! 2: !core2! 3: !core3! | [FAN] !fan1!\n"; | |
#### | |
sub doFConv { | |
my ($tempstr) = @_; | |
return $tempstr if !$USEF; | |
if ($tempstr =~ /\d+\.?\d*/) { | |
$tempstr =~ s/°C//; | |
$tempstr = (9 * $tempstr/5)+32; | |
return $tempstr."°F"; | |
} | |
} | |
my @sensorsData = `sensors`; | |
my %sensors; | |
my $cnt = 0; | |
my $tmp; | |
foreach my $line (@sensorsData) { | |
if ($line =~ /(\w+)\:(.*)/) { | |
$tmp = $2; | |
next if ($1 =~ m/Adapter/); | |
if ($cnt <= 5) { | |
$tmp =~ s/\+//; | |
$tmp =~ s/\s+//gs; | |
$tmp =~ s/\(high.*\)//; | |
} | |
if ($cnt == 1) { | |
$sensors{cputemp} = doFConv $tmp; | |
} elsif ($cnt == 2) { | |
$sensors{core0} = doFConv $tmp; | |
} elsif ($cnt == 3) { | |
$sensors{core1} = doFConv $tmp; | |
} elsif ($cnt == 4) { | |
$sensors{core2} = doFConv $tmp; | |
} elsif ($cnt == 5) { | |
$sensors{core3} = doFConv $tmp; | |
} else { | |
$sensors{$1} = $tmp; | |
} | |
} | |
$cnt++; | |
} | |
while ($OUT =~ /!(\w+)\!/) { | |
if ($sensors{$1}) { | |
my $op = $1; | |
$sensors{$op} =~ s/\s+//; | |
$OUT =~ s/\!$op\!/$sensors{$op}/; | |
} | |
} | |
print $OUT; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment