#!/bin/bash awk ' BEGIN { cmd = "lsof -FpRgcLtn" while ((cmd | getline field) > 0){ fieldtype = substr(field,1,1) sub("^.","",field) if ("p" == fieldtype) { pid = field } else if ("R" == fieldtype) { ppid = field } else if ("g" == fieldtype) { gpid = field } else if ("c" == fieldtype) { command = field } else if ("L" == fieldtype) { login = field } else if ("t" == fieldtype) { type = field } else if ("n" == fieldtype) { if ( split(field, a, " \\(deleted\\)$")>1 ) { file = a[1] deleted = 1 } else { file = field deleted = 0 } if ( (type == "DEL") && (substr(file,1,5) != "/SYSV") \ ||(deleted == 1) \ ) { display_deleted(command, login, pid, gpid, file) } } } close(cmd) } function display_deleted( command, login, pid, gpid, file ) { printf("Program %s (user: %s, pid: %d, process group id: %d) is using a deleted file: %s\n", command, login, pid, gpid, file) } '