LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Automated build and email log in bash (https://www.linuxquestions.org/questions/linux-server-73/automated-build-and-email-log-in-bash-535651/)

sardaukar_siet 03-08-2007 05:48 AM

Automated build and email log in bash
 
Hello!

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 :

Code:

#!/bin/bash

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

cvs -z9 -d:pserver:anonymous@cvs.sv.gnu.org:/sources/mldonkey co -P mldonkey
cd mldonkey
./configure
make
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 11:59 AM

Got it! :D

Code:

#!/bin/bash

# Automated MLDonkey build script - sardaukar.siet@gmail.com

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
fi

cd /root
cvs -z9 -d:pserver:anonymous@cvs.sv.gnu.org:/sources/mldonkey 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 ;
}
else
        echo "$START

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

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



All times are GMT -5. The time now is 07:51 PM.