Koozali.org: home of the SME Server

Legacy Forums => General Discussion (Legacy) => Topic started by: BobWilliams on November 09, 2004, 05:28:02 PM

Title: Need crontab script to send email notices to admin
Post by: BobWilliams on November 09, 2004, 05:28:02 PM
I need to create a script to have Crontab execute a job that emails the output of say "df -h" to the admin account field 'forwarding address for administrative messages' but I don't know the script commands. Can anyone help me?

Bob...
Title: Need crontab script to send email notices to admin
Post by: Kobus on November 11, 2004, 11:44:37 PM
you could always write the output of df to a file and then use mail to send it to an email address.

shove it into cron and you should get regula emails
Title: Need crontab script to send email notices to admin
Post by: BobWilliams on November 11, 2004, 11:55:55 PM
Thanks for the reply kbensch. I did just that.
'date' > /df-test
mail -s "subject" mail-address < /df-test
and used the new SME Server Manager - Crontab Manager panel to launch the script. Works great.

Bob...
Title: Need crontab script to send email notices to admin
Post by: monkey on November 13, 2004, 05:34:26 AM
I have a script for emailing ping logs to my email address for work. Its a bit crude, but works.

Code: [Select]

FROMMAIL="XXXXXXXXX@XXXXXX.com"
TOMAIL="XXXXXXXXXX@XXXXXX.com"
MAILFILE=/tmp/basename ${0}.$$

PINGLOG="/export/home/szr52z/log/vpn_log.txt"

SentPage() {

        DATE=date "+%H:%m %Y-%m-%d"

        echo "From: ${FROMMAIL}"                                > ${MAILFILE}
        echo "To: ${TOMAIL}"                                    >> ${MAILFILE}
        echo "Subject: [VPN Ping Report]."          >> ${MAILFILE}
        echo "Content-Type: text/plain; charset=us-ascii"       >> ${MAILFILE}
        echo "Content-Transfer-Encoding: 7bit\n\n"              >> ${MAILFILE}

        echo " "                                                >> ${MAILFILE}
        echo "Time stamp: ${DATE}."                             >> ${MAILFILE}
        echo " "                                                >> ${MAILFILE}

        echo "The failed ping attempts are as follows:"         >> ${MAILFILE}
        echo " "                                                >> ${MAILFILE}
        echo "-----------"                                      >> ${MAILFILE}

/usr/bin/cat ${PINGLOG} >> ${MAILFILE}

        /usr/lib/sendmail -oi -t -oem < ${MAILFILE}
}

main() {

        if [ "${PINGLOG}" != "" ] ; then
                SentPage
        fi
}

main


Tho SME doesn't have send mail, it might help give an idea atleast.
Title: Need crontab script to send email notices to admin
Post by: BobWilliams on November 13, 2004, 02:34:47 PM
Thanks for the input monkey. That script will be a great help to me learning scripting on SME. I think this product is great and the support the members provide is outstanding.

Thanks

Bob...