From 696e05f39721b96a278bb6e6ac2f8dbe64235621 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 24 Oct 2010 14:46:49 +0200 Subject: Add hddtemp wrapper --- bin/vdf | 2 +- bin/vhddtemp | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100755 bin/vhddtemp diff --git a/bin/vdf b/bin/vdf index b24147d..4fd7770 100755 --- a/bin/vdf +++ b/bin/vdf @@ -83,7 +83,7 @@ sub show_df_console { getopts('ac', \%opts); -open(my $mounts_fh, '/proc/mounts'); +open(my $mounts_fh, '<', '/proc/mounts'); while (my $line = <$mounts_fh>) { push(@mounts, [split(qr{ }, $line)]); } diff --git a/bin/vhddtemp b/bin/vhddtemp new file mode 100755 index 0000000..99bc0cc --- /dev/null +++ b/bin/vhddtemp @@ -0,0 +1,93 @@ +#!/usr/bin/env perl +## Copyright © 2010 by Daniel Friesel +## License: WTFPL +## 0. You just DO WHAT THE FUCK YOU WANT TO. +use strict; +use warnings; +use 5.010; + +use autodie; + +use GD; +use Getopt::Std; +use Term::ANSIColor; + +my %temperature; +my %opts; + +sub get_temp { + my ($disk) = @_; + + chomp(my $temp = qx{/usr/sbin/hddtemp -n SATA:/dev/${disk}}); + + if (length($temp) == 0 or $temp !~ qr{ ^ \d+ $ }x) { + $temp = undef; + } + + $temperature{"$disk"} = $temp; +} + +sub show_console { + foreach my $disk (sort keys %temperature) { + + my $t = $temperature{"$disk"}; + print colored("${disk} ", 'reset'); + + given ($t) { + when (undef) { say "???" } + + when ($_ <= 25) { say colored("${t}c", 'blue') } + when ($_ <= 40) { say colored("${t}c", 'green') } + when ($_ <= 50) { say colored("${t}c", 'yellow') } + default { say colored("${t}c", 'red') } + } + } + return; +} + +getopts('c', \%opts); + +opendir(my $disk_dh, '/sys/block'); +foreach my $disk (readdir($disk_dh)) { + if ($disk !~ qr{ ^ sd [a-z] $ }x) { + next; + } + open(my $cap_fh, '<', "/sys/block/${disk}/capability"); + my $cap = <$cap_fh>; + close($cap_fh); + if ($cap ~~ [10, 12, 50, 52]) { + get_temp($disk); + } +} +closedir($disk_dh); + +if ($opts{'c'}) { + show_console(); +} + + +__END__ + +=head1 NAME + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +=head1 OPTIONS + +=head1 EXIT STATUS + +=head1 CONFIGURATION + +=head1 DEPENDENCIES + +=head1 BUGS AND LIMITATIONS + +=head1 AUTHOR + +Copyright (C) 2010 by Daniel Friesel Ederf@finalrewind.orgE + +=head1 LICENSE + + 0. You just DO WHAT THE FUCK YOU WANT TO. -- cgit v1.2.3