summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2018-04-14 14:17:56 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2018-04-14 14:17:56 +0200
commit3bb2f9a6caef07cd2d798fe52e340df524663a82 (patch)
tree4b7efc82afb7c02b6120a548b5578abdeecc9f84
parent3fc89b51602f48938dcaa3d272fce130cd674093 (diff)
downloadutils-3bb2f9a6caef07cd2d798fe52e340df524663a82.tar
utils-3bb2f9a6caef07cd2d798fe52e340df524663a82.tar.gz
utils-3bb2f9a6caef07cd2d798fe52e340df524663a82.tar.bz2
utils-3bb2f9a6caef07cd2d798fe52e340df524663a82.tar.xz
utils-3bb2f9a6caef07cd2d798fe52e340df524663a82.zip
monitor-uucp
-rwxr-xr-xmonitor-uucp64
-rw-r--r--nix/default.nix1
-rw-r--r--nix/monitor-uucp.nix29
3 files changed, 94 insertions, 0 deletions
diff --git a/monitor-uucp b/monitor-uucp
new file mode 100755
index 0000000..412c707
--- /dev/null
+++ b/monitor-uucp
@@ -0,0 +1,64 @@
1#!@zsh@/bin/zsh
2
3lsof() { @lsof@/bin/lsof ${@} 2>/dev/null | tail -n +2}
4ignoredFiles() {
5 cat <<EOF
6^/usr/
7^/lib
8^/dev/
9^pipe$
10^/$
11^/etc/
12^/var/log/
13EOF
14}
15
16slept=0
17sleep=0.5
18sleepTimeout=30
19watched=false
20
21while true; do
22 typeset -a files
23 files=()
24
25 used=$(lsof -c uucico -c uux | awk '{ $1=$2=$3=$4=$5=$6=$7=$8=""; print $0; }' | sed -r 's/^\s+//')
26
27 files=(${(f)used})
28
29 watched=false
30
31 for file (${files}); do
32 line=$(lsof ${file} | grep -E '^(uucico|uux) ')
33 line() { print ${line} }
34
35 print ${file} | grep -qEf =(ignoredFiles) && continue
36 [[ -z $(line) ]] && continue
37
38 fType=$(line | awk '{ print $5; }')
39 size=$(line | awk '{ print $7; }')
40 pid=$(line | awk '{ print $2; }')
41 fd=$(line | awk '{ print $4; }' | tr -dc '[:digit:]')
42 name=$(basename ${file} | awk -v len=19 '{ if (length($0) > len) print substr($0, 1, len-3) "..."; else print; }')
43
44 [[ ${fType} == "REG" ]] || continue
45
46 clear
47 @pv@/bin/pv -W -D 2 -i 0.5 -d ${pid}:${fd} -s ${size} -F "%r %a %p %e %I" -p -r -I -e -N ${name}
48
49 slept=0
50 watched=true
51
52 break
53 done
54
55 if $watched || [[ $slept -ge $(($sleepTimeout / $sleep)) ]]; then
56 printf "inotify (%s)\n" $(date +"%T")
57 @inotify@/bin/inotifywait -r -e access /var/spool/uucp &>/dev/null
58 slept=0
59 else
60 sleep 0.1
61 printf "."
62 slept=$(($slept + 1))
63 fi
64done
diff --git a/nix/default.nix b/nix/default.nix
index ad181fa..1c0105f 100644
--- a/nix/default.nix
+++ b/nix/default.nix
@@ -6,4 +6,5 @@ in rec {
6 cliparg = pkgs.callPackage ./cliparg.nix {}; 6 cliparg = pkgs.callPackage ./cliparg.nix {};
7 rebuild-system = pkgs.callPackage ./rebuild-system.nix {}; 7 rebuild-system = pkgs.callPackage ./rebuild-system.nix {};
8 pulseaudio-ctl = pkgs.callPackage ./pulseaudio-ctl.nix {}; 8 pulseaudio-ctl = pkgs.callPackage ./pulseaudio-ctl.nix {};
9 monitor-uucp = pkgs.callPackage ./monitor-uucp.nix {};
9} 10}
diff --git a/nix/monitor-uucp.nix b/nix/monitor-uucp.nix
new file mode 100644
index 0000000..b1abdda
--- /dev/null
+++ b/nix/monitor-uucp.nix
@@ -0,0 +1,29 @@
1{ stdenv
2, fetchgit
3, makeWrapper
4, zsh, lsof, pv, inotify-tools
5}:
6
7stdenv.mkDerivation rec {
8 name = "monitor-uucp-${version}";
9 version = "0.1";
10 src = ../monitor-uucp;
11
12 buildInputs = [ makeWrapper ];
13
14 phases = [ "buildPhase" "installPhase" ];
15
16 inherit zsh lsof pv;
17 inotify = inotify-tools;
18
19 buildPhase = ''
20 substituteAll $src monitor-uucp
21 '';
22
23 installPhase = ''
24 mkdir -p $out/bin
25
26 install -m 755 -t $out/bin \
27 monitor-uucp
28 '';
29}