]> Git — Sourcephile - sourcephile-nix.git/blob - pkgs/tools/system/smartmontools/smartctl-tbw/default.nix
mermet: fix dovecot and postfix
[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 PATH = stdenv.lib.concatStringsSep ":"
11 [ "${coreutils}/bin"
12 "${gawk}/bin"
13 "${gnused}/bin"
14 "${sudo}/bin"
15 "${utillinux}/bin"
16 ];
17 in
18 writeShellScriptBin "smartctl-tbw" ''
19 export PATH=${PATH}
20 device=''${1:-/dev/sda}
21 sudo ${smartmontools}/bin/smartctl -A $device |
22 { awk '
23 $0 ~ /Power_On_Hours/ { poh=$10; printf "%s / %d hours / %d days / %.2f years\n", $2, $10, $10 / 24, $10 / 24 / 365.25 }
24 $0 ~ /Total_LBAs_Written/ {
25 lbas = $10;
26 bytes = $10 * 512;
27 mb = bytes / 1024^2;
28 gb = bytes / 1024^3;
29 tb = bytes / 1024^4;
30 printf "%s / %s / %d mb / %.1f gb / %.3f tb\n", $2, $10, mb, gb, tb
31 printf "mean writes per hour: / %.2f", mb/poh
32 }
33 $0 ~ /Airflow_Temperature_Cel/ { print $2 " / " $10}
34 $0 ~ /Wear_Leveling_Count/ { printf "%s / %d (%% health)\n", $2, int($4) }
35 '; echo; } |
36 sed -e 's:/:@:' |
37 sed -e "s\$^\$$device @ \$" |
38 column -ts@
39 ''