]> Git — Sourcephile - sourcephile-nix.git/blob - pkgs/tools/system/smartmontools/smartctl-tbw/default.nix
nix: add admin tools and setup shorewall
[sourcephile-nix.git] / pkgs / tools / system / smartmontools / smartctl-tbw / default.nix
1 { coreutils
2 , gawk
3 , gnused
4 , smartmontools
5 , stdenv
6 , sudo
7 , writeShellScriptBin
8 , utillinux
9 }:
10 let
11 PATH = stdenv.lib.concatStringsSep ":"
12 [ "${coreutils}/bin"
13 "${gawk}/bin"
14 "${gnused}/bin"
15 "${sudo}/bin"
16 "${utillinux}/bin"
17 ];
18 in
19 stdenv.mkDerivation rec {
20 pname = "smartctl-tbw";
21 version = "1.0";
22 name = "${pname}-${version}";
23
24 src = writeShellScriptBin "smartctl-tbw" ''
25 export PATH=${PATH}
26 device=''${1:-/dev/sda}
27 sudo ${smartmontools}/bin/smartctl -A $device |
28 awk '
29 $0 ~ /Power_On_Hours/ { poh=$10; printf "%s / %d hours / %d days / %.2f years\n", $2, $10, $10 / 24, $10 / 24 / 365.25 }
30 $0 ~ /Total_LBAs_Written/ {
31 lbas=$10;
32 bytes=$10 * 512;
33 mb= bytes / 1024^2;
34 gb= bytes / 1024^3;
35 tb= bytes / 1024^4;
36 printf "%s / %s / %d mb / %.1f gb / %.3f tb\n", $2, $10, mb, gb, tb
37 printf "mean writes per hour: / %.2f", mb/poh
38 }
39 $0 ~ /Airflow_Temperature_Cel/ { print $2 " / " $10}
40 $0 ~ /Wear_Leveling_Count/ { printf "%s / %d (%% health)\n", $2, int($4) }
41 ' |
42 sed -e 's:/:@:' |
43 sed -e "s\$^\$$device @ \$" |
44 column -ts@
45 '';
46
47 buildInputs = [
48 gawk
49 coreutils
50 gnused
51 smartmontools
52 sudo
53 utillinux
54 ];
55 installPhase = ''
56 cp -r . $out
57 '';
58
59 meta = {
60 description = "Wrapper around smartctl to print the Total-Bytes-Written of disks";
61 license = stdenv.lib.licenses.gpl3Plus;
62 platforms = stdenv.lib.platforms.all;
63 };
64 }