diff options
author | Andrew Cady <d@jerkface.net> | 2020-10-10 20:21:48 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2020-10-10 20:21:48 -0400 |
commit | 66b5173003d6c9c4bc205f71c987828ec546d239 (patch) | |
tree | 5d9c007d1b2f3c88fd877a47a71ddd6ff2ea0763 | |
parent | 7e58194eb06762d7e6a99558dfe90e6485da89aa (diff) |
util: watch-entropy
-rwxr-xr-x | src/watch-entropy | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/watch-entropy b/src/watch-entropy new file mode 100755 index 0000000..e0f3261 --- /dev/null +++ b/src/watch-entropy | |||
@@ -0,0 +1,19 @@ | |||
1 | #!/usr/bin/perl | ||
2 | $SIG{INT} = sub { ++$interrupted; }; | ||
3 | use Time::HiRes qw(sleep); | ||
4 | use constant default_file => "/proc/sys/kernel/random/entropy_avail"; | ||
5 | use constant default_format => 'system entropy: %-5d bits'; | ||
6 | $|++; | ||
7 | my $file = shift || default_file; | ||
8 | my $format = $file eq default_file ? default_format : "$file: %s"; | ||
9 | my $sleep_time = shift || 0.2; | ||
10 | open ENT, "<", $file or die "$0: error opening $file: $!\n"; | ||
11 | my $last; while (<ENT>) { | ||
12 | chomp; | ||
13 | printf " $format", $_ . (" " x (length($last) - length $_)) unless $_ eq $last; | ||
14 | $last = $_; | ||
15 | last if $interrupted; | ||
16 | sleep $sleep_time; | ||
17 | seek ENT, 0, 0; | ||
18 | } | ||
19 | print "\n"; | ||