What directory PHP is busy with

The file “cwd” under /proc/pid is a symbolic link to the “current working directory”:

for i in `ps -ef | awk '/php/{print $2}'`
do
ls -l /proc/${i}/cwd
done

The result is:

lrwxrwxrwx 1 alekz alekz 0 Янв 25 02:40 /proc/11544/cwd -> /home/alekz/public_html/blog/wp
lrwxrwxrwx 1 alekz alekz 0 Янв 25 02:40 /proc/11764/cwd -> /home/alekz/public_html/alekz.net
lrwxrwxrwx 1 alekz alekz 0 Янв 25 02:40 /proc/12574/cwd -> /home/alekz/public_html/alekz.net
lrwxrwxrwx 1 alekz alekz 0 Янв 25 02:40 /proc/13081/cwd -> /home/alekz/public_html/alekz.net
lrwxrwxrwx 1 alekz alekz 0 Янв 25 02:45 /proc/15053/cwd -> /home/alekz/public_html/blog/wp
lrwxrwxrwx 1 alekz alekz 0 Янв 25 02:45 /proc/15056/cwd -> /home/alekz/public_html/blog/wp
lrwxrwxrwx 1 alekz alekz 0 Янв 25 02:49 /proc/15696/cwd -> /home/alekz/public_html/blog/wp/wp-content/plugins/si-captcha-for-wordpress/captcha-secureimage

Of course, you can use any other process name instead of php.

And here’s a “dynamic” version:

while true
do
clear
for i in `ps -ef | awk '/php/{print $2}'`
do
ls -l /proc/${i}/cwd
done
sleep 5
done

Short script for searching mail logs

Today I had to search through dozens of mail logs (syslog) located on several mail relays and find all entries related to a particular user.

Given:

  • All servers are managed via a remote tty console,
  • The ksh-script must be copy&pasteable
  • All logs are gzipped
  • I need all entries with the same message number (the ninth field) as the found log entry

This is what I came up with:

Continue reading “Short script for searching mail logs”