Bonsoir!
j’ai écrit un script permettant de savoir combien de nouveaux mails j’ai sur mes boites. Cependant, il est sûrement un peu lourd. Pourriez-vous me le corriger et me dire comment l’améliorer?
le voici :
[code]#!/bin/sh
#script pour vérifier mes mails sur les 2 boites.
#Le fichier de configuration est ~/.fetchmail/fetchmailrc
#On vérifie que le script ne tourne pas déjà
_PS=ps aux
_PID=echo "${_PS}" | grep $0 | tr -s [:space:] | cut -d' ' -f2
_LINES=echo "${_PID}" | wc -w
if [ ${_LINES} -gt 1 ]; then
_PID=echo ${_PID} | cut -d' ' -f1
echo "Un script en trop, on le kill (pid: ${_PID})"
kill ${_PID}
fi
while true; do
TEST=$(ping -c1 www.google.fr | grep received | awk ‘{print $5}’)
if [ -e /tmp/mails ]; then
rm /tmp/mails
fi
if [ “$TEST” = “received,” ]; then
TOTGMAIL="$(fetchmail -c -p IMAP imap.gmail.com --port 993 --ssl --username xavier.cartron -f .fetchmail/fetchmailrc | tail -n 1 | awk ‘{print $1}’)“
LUGMAIL=”$(fetchmail -c -p IMAP imap.gmail.com --port 993 --ssl --username xavier.cartron -f .fetchmail/fetchmailrc | tail -n 1 | awk ‘{print $3}’ | sed ‘s/(//’)“
NGMAIL=$(($TOTGMAIL - $LUGMAIL))
TOTFAC=”$(fetchmail -c -p IMAP imaps.etu.univ-nantes.fr --port 993 --ssl --username e072767U -f .fetchmail/fetchmailrc | tail -n 1 | awk ‘{print $1}’)“
LUFAC=”$(fetchmail -c -p IMAP imaps.etu.univ-nantes.fr --port 993 --ssl --username e072767U -f .fetchmail/fetchmailrc | tail -n 1 | awk ‘{print $3}’ | sed ‘s/(//’)"
NFAC=$(($TOTFAC - $LUFAC))
echo -n " | Gmail:$NGMAIL-" >> /tmp/mails
echo -n "Fac:$NFAC | " >> /tmp/mails
else
echo " | Mails:??? | " > /tmp/mails
fi
sleep 300
done
else
exit
[/code]