Fun thing in shell script, any idea?
2007-12-24 19:22:00
with the script pasted under these line I encounter *fun* things.
It works well when you execute it, but once in the crontab it reports errors
!
Here is the line in the crontab :
0 7,12,17 * * * /usr/local/bin/process
Here is the error message :
From root Fri Feb 9 17:16:02 2001
Date: Fri, 9 Feb 2001 17:16:02 +0100
From: root (Super-User)
Message-Id: <32413543213654635.RA324654 at xxxxxxxx.>
To: root
Subject: Output from "cron" command
Content-Length: 493
Your "cron" job on xxxxxxxxx
/usr/local/bin/process
produced the following output:
/usr/local/bin/process[4]: ::::::::::::::: not found
/usr/local/bin/process[4]: /tmp/.proc: cannot execute
/usr/local/bin/process[4]: ::::::::::::::: not found
And here is the script :
(Note : if you change more by cat in the for condition, it works really
nicely).
#!/usr/bin/ksh
#process
##################
#variables
##################
#processus a surveiller et a remonter le cas echeant
#Pour ajouter des lignes, suivre le modele ci-dessous
echo "/usr/sbin/auditd" > /tmp/.proc
echo "/usr/sbin/cron" >> /tmp/.proc
echo "/usr/sbin/sshd" >> /tmp/.proc
echo "/usr/lib/snmp/snmpdx" >> /tmp/.proc
##################
#functions
##################
#relance le process avec si besoins ses options (a preciser au cas
par cas).
function arguments
{
case $1 in
/usr/lib/snmp/snmpdx) /usr/lib/snmp/snmpdx -y -c
/etc/snmp/conf;;
*) $1;;
esac
}
#envoi un mail d'avertissement et appel la fonction arguments
function relance
{
dat=`date '+%d/%m %H:%M'`
#Envoi de mail a tous les administrateurs
#recuperation de l'ensemble des administrateurs
for adm in `more /etc/passwd |grep administrateur |cut -f1 -d:`
do
mail $adm << EOF
le $dat
ATTENTION !!!
le processus $1 est tombe et viens d'etre relance.
Penser a regarder les causes possibles de cette erreur.
EOF
done
echo "Dans Relance"
arguments $1
}
##################
#main
##################
for l in `more /tmp/.proc`
do
pr=`ps -ef |grep $l|grep -v grep|wc -l`
echo "pr=$pr"
echo "l=$l"
if [ $pr -eq 0 ]
then
relance $l
fi
done
rm /tmp/.proc
Does anyone got an idea why it repports an error ?
(yes I know that root is not made for running script, yet I do it ;)
Thanks ;)
Sbastien Devaux
Junior Sys Admin
France
Comments
Got something to say?
You must be logged in to post a comment.

