-   Linux - Server (
-   -   Automated build and email log in bash (

sardaukar_siet 03-08-2007 06:48 AM

Automated build and email log in bash

I have a specific need for a script :

1. extract latest CVS
2. build the extracted snapshot (configure + make)
3. if successful, stop service, copy generated binary to a directory, restart service
4. mail me all output + time taken in each step (cvs retrieval, configure and make) + is service running

So far, I have 1 and 2 running :



# Automatic MLDonkey compilation from CVS
# Run as root in home directory

cvs -z9 co -P mldonkey
cd mldonkey
echo "MLDonkey build complete."

What is the best way to implement the remaining steps? Also, if I run this as a cron job, will I get two mails (from successful cronjob + script's own mail) ?

Thanks for any help!

sardaukar_siet 03-08-2007 12:59 PM

Got it! :D



# Automated MLDonkey build script -

MESSAGE="step incomplete"

echo $MESSAGE > /tmp/cvs-update.log
echo $MESSAGE > /tmp/configure.log
echo $MESSAGE > /tmp/make.log

START='build started '`date +"%m-%d-%Y %T"`

if [ -e /root/mldonkey/mlnet ]; then
rm /root/mldonkey/mlnet

cd /root
cvs -z9 co -P mldonkey &> /tmp/cvs-update.log && cd mldonkey && ./configure &> /tmp/configure.log && make &> /tmp/make.log

END='build ended '`date +"%m-%d-%Y %T"`

EMAIL="your email here"

if [ -e /root/mldonkey/mlnet ]; then
        SUM=`md5sum /root/mldonkey/mlnet | cut -d " " -f1`;
        echo "$START

$END" | mutt -s "mldonkey build successful [$SUM]" $EMAIL -a /tmp/cvs-update.log -a /tmp/configure.log -a /tmp/make.log ;
        echo "$START

$END" | mutt -s "mldonkey build failed" $EMAIL -a /tmp/cvs-update.log -a /tmp/configure.log -a /tmp/make.log

rm /tmp/cvs-update.log
rm /tmp/configure.log
rm /tmp/make.log

All times are GMT -5. The time now is 03:23 AM.