With the script below, a search is made to all the existing properties in the indicated directory in order to obtain the email addresses associated with each hosting:
#!/bin/bash
# Scan All available email account addresses
# for homedir under the provided path
# 2014-12-19 Salustiano Silva
# Control :: Provided directory supplied ?
if [ -z "$1" ]; then
echo "É preciso passar como parâmetro o caminho completo para a diretoria 'home'!"
exit
fi
HOMEDIR="$1"
# Control :: Provided directory exists ?
if [ ! -d "$HOMEDIR" ]; then
echo "A diretoria $HOMEDIR não foi localizada, verifique os dados fornecidos!"
exit
fi
HOMEDIR="$1"
CPANELUSERS='ls -1A /var/cpanel/users/'
count=1
for x in 'echo -n "$CPANELUSERS"';do
wiersz='grep -i ^dns /var/cpanel/users/"$x" |cut -d= -f2'
DOMAIN[$count]=$wiersz
count=$[$count+1]
echo "Login: 'echo "$x"'"
for i in 'echo "${DOMAIN[@]}" | sed 's/ /\n/g'';do
for n in ' ls -A "$HOMEDIR""$x"/mail/"$i"/ 2>/dev/null';do
if [ "$n" == "cur" ];then echo "$n" > /dev/null
elif [ "$n" == "new" ];then echo "$n" > /dev/null
elif [ "$n" == "tmp" ];then echo "$n" > /dev/null
elif [ "$n" == "" ];then echo "$n" > /dev/null
else
echo "$n"@"$i"
fi
done
done
echo;echo;
done
Example usage:
./getMails /home/ > lista.txt
Result in file lista.txt
:
Login: example
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
Login: test
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
Question
How can I prevent the script from following symbolic links to other locations by performing the search only with "regular" directories?