[Nottingham] bash syntax: elif

David Wolfson eaxdrw at nottingham.ac.uk
Tue Jul 27 10:00:14 BST 2004


In my continuing quest to automate some of the tasks on our shared machine, I've persuaded it to run a virus sweep all on its own (clever little chap isn't it!).  I can even get it to mail me if it works ok.  What I'd like it to do is send a different mail if detects a virus, or if it encounters errors.  I think this should be possible as the man file for the virus software lists diffent error codes for different outcomes:

       0      If no errors are encountered and no viruses are found.
       1      If  the user interrupts SWEEP (usually by pressing control-C) or
              kills the process.
       2      If some error preventing further execution is discovered.
       3      If viruses or virus fragments are discovered.

At the moment I use the following mail loop:

if [ $? -eq 0 ]
then 
echo 'pepdm1 virus sweep clear'|mail -s 'sweep' eaxdrw at nottingham.ac.uk 
else
echo 'pepdm1 virus sweep error'|mail -s 'sweep' eaxdrw at nottingham.ac.uk 
fi

but tried changing it to this:

if [ $? -eq 0 ]
	then 
	echo 'pepdm1 virus sweep clear'|mail -s 'sweep' eaxdrw at nottingham.ac.uk 
elif [$? -eq 1 ]
	then
	echo 'pepdm1 virus sweep interupted'|mail -s 'sweep' eaxdrw at nottingham.ac.uk 
elif [$? -eq 2 ]
	then
	echo 'pepdm1 virus sweep error'|mail -s 'sweep' eaxdrw at nottingham.ac.uk 
elif [$? -eq 3 ]
	then
	echo 'pepdm1 virus detected'|mail -s 'sweep' eaxdrw at nottingham.ac.uk 
fi

and got no mail at all.  I'm guessing that I have something wrong in the elif syntax but a quick google only seemed to get me very specific questions on user forums.  Can anyone either point out the obvious errors, or suggest an intermediate bash help site please?

Thanks as ever,

Dave


This message has been scanned but we cannot guarantee that it and any
attachments are free from viruses or other damaging content: you are
advised to perform your own checks.  Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.




More information about the Nottingham mailing list