diff options
| -rwxr-xr-x | monitor-uucp | 64 | ||||
| -rw-r--r-- | nix/default.nix | 1 | ||||
| -rw-r--r-- | nix/monitor-uucp.nix | 29 | 
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 | |||
| 3 | lsof() { @lsof@/bin/lsof ${@} 2>/dev/null | tail -n +2} | ||
| 4 | ignoredFiles() { | ||
| 5 | cat <<EOF | ||
| 6 | ^/usr/ | ||
| 7 | ^/lib | ||
| 8 | ^/dev/ | ||
| 9 | ^pipe$ | ||
| 10 | ^/$ | ||
| 11 | ^/etc/ | ||
| 12 | ^/var/log/ | ||
| 13 | EOF | ||
| 14 | } | ||
| 15 | |||
| 16 | slept=0 | ||
| 17 | sleep=0.5 | ||
| 18 | sleepTimeout=30 | ||
| 19 | watched=false | ||
| 20 | |||
| 21 | while 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 | ||
| 64 | done | ||
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 | |||
| 7 | stdenv.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 | } | ||
