Various nuggets of useful technical information.

Tuesday, June 24, 2008

Looking for Users on Mailserver in Linux

Linux mail servers have users' home directories in /home

Within the various user folders there may be .copy and .forward files that reference other user accounts by email address.

In addition users may be aliased in /etc/aliases

When a user gets deleted, they may still be referenced in a .copy, .procmailrc or .forward file somewhere or exist in the aliases db

Use the following script to check for a user's presence in one quick step:

#!/bin/bash

# This script helps search for usernames that are being copied, forwarded or
# aliased to.

USERNAME=$1;

# Go to the /home driectory
cd /home

# Search all .copy files and print the name out of the file that matches
echo ".copy references: "
grep -l $USERNAME `ls */.copy`
echo -e "\n"

# Same for .forward files
echo ".forward references: "
grep -l $USERNAME `ls */.forward`
echo -e "\n"

# Same for .procmailrc files
echo ".procmailrc references: "
grep -l $USERNAME `ls */.procmailrc`
echo -e "\n"

# Same for the /etc/aliases file
echo "Aliases File: "
cat /etc/aliases | grep $USERNAME
echo -e "\n"


I put this file in /root/bin as well. If you change this location, make sure you change the location in the script above.

No comments: