#!/bin/sh # A small shell script to raid the /proc dir to find all cwds of # current processes. # Errors and output are deleted unless the script is called with an # argument of "-d". # By Emarit Ranu ranu@engr.ColoState.EDU # v0.1 26-Oct-97 Created script. # v0.2 28-Oct-97 Added line formatting (uses too many command execs). # v0.21 1-Nov-97 Removed path specifications. # v0.22 2-Nov-97 Finds and uses system pwd NOT shell pwd. # Copying policy: Freeware but I prefer to maintain it. # Disclaimer: There is no warranty. I am not responsible for desired or # undesired results from using this script. In fact, I am not responsible # at all - for anything, anytime! # If you make a change that you think improves this tiny script, let me # know and maybe I'll incorperate it. If I do, you'll be given due credit. # Change $pager if you like 'more' or something else. ver=0.22 pager=less pwd=`which pwd` echo echo "procdirs version $ver" echo if [ "$1" = "-d" ] then echo -n "Debug mode." fi cd /proc find ./ * -print | grep cwd > /tmp/pdthedirs 2> /tmp/pdfind-errors a=`cat /tmp/pdthedirs` echo "PID Current working directory" >> "/tmp/pdprocdirs" for i in $a; do pid=`echo $i | cut -d"/" -f1` cd /proc; echo -n "$pid " >> /tmp/pdprocdirs; cd $i 2>> /tmp/pdcderrors; awk -v i="$pid" 'BEGIN { if (length(i) == 1) printf(" ") >> "/tmp/pdprocdirs" if (length(i) == 2) printf(" ") >> "/tmp/pdprocdirs" if (length(i) == 3) printf(" ") >> "/tmp/pdprocdirs" if (length(i) == 4) printf(" ") >> "/tmp/pdprocdirs" if (length(i) == 5) printf(" ") >> "/tmp/pdprocdirs" }' # If you dabbled with the source so your PIDs can be >99999 (I don't even # know if you can), then add another if statement above. $pwd >> /tmp/pdprocdirs 2>> /tmp/pdpwderrors; echo -n "." done echo rm -f /tmp/pdthedirs $pager /tmp/pdprocdirs if [ "$1" = "-d" ] then echo echo "Error outputs and process cwds captured in /tmp." echo exit else rm -f /tmp/pdpwderrors rm -f /tmp/pdfind-errors rm -f /tmp/pdcderrors rm -f /tmp/pdprocdirs fi