Have a question about CiviCRM? Get it answered quickly at the new CiviCRM Stack Exchange Q+A siteThis forum was archived on 25 November 2017. Learn more.How to get involved.What to do if you think you've found a bug.
#!/bin/bash## Configuration parameters used by the CiviCRM scripts#TmpDirectory= # Directory for temporary files (need rw access)TheHost= # eg, http://google.comThePath=/administrator/components/com_civicrm/civicrm/binTheUser= # Supply credentials for the Joomla! userThePass= # under whom the scripts are executed,TheKey= # plus the CiviCRM key
#!/bin/bash## This script will send CiviMail emails.# It does this by invoking the appropriate CiviCRM PHP script.# If anything unusual happens, a mail is sent to the system administrator#Program="CiviMail send wrapper"Directory=`dirname $0`. $Directory/configuration.shSendUrl="${TheHost}${ThePath}/civimail.cronjob.php?name=${TheUser}&pass=${ThePass}&key=${TheKey}"FilePattern=$TmpDirectory/`basename $0`.$$Document=${FilePattern}.documentLog=${FilePattern}.logwget "${SendUrl}" --output-document=$Document --output-file=$LogResult=$?if [[ $Result != 0 ]]then echo Failed to connect to CiviCRM echo ' ' echo ---- Return-code returned by wget ---- echo $Result echo ' ' echo ---- Contents of wget log ---- cat $Logelif [[ -s $Document ]]then echo CiviCRM returned a non-empty result echo ' ' echo ---- Response from CiviCRM ---- cat $Document echo ' ' echo ---- Contents of wget log ---- cat $Logelif [[ ! -e $Document ]]then echo CiviCRM did not return a result echo ' ' echo ---- Contents of wget log ---- cat $Logfirm -f $Document $Log
#!/bin/bash## This script will receive CiviMail emails.# It does this by invoking the appropriate CiviCRM PHP script.# If anything unusual happens, a mail is sent to the system administrator#Program="CiviMail receive wrapper"Directory=`dirname $0`. $Directory/configuration.shReceiveUrl="${TheHost}${ThePath}/CiviMailProcessor.php?name=${TheUser}&pass=${ThePass}&key=${TheKey}"FilePattern=$TmpDirectory/`basename $0`.$$Document=${FilePattern}.documentLog=${FilePattern}.logStatusLog=${FilePattern}.status.logwget "${ReceiveUrl}" --output-document=$Document --output-file=$LogResult=$?if [[ $Result != 0 ]]then echo Failed to connect to CiviCRM echo ' ' echo ---- Return-code returned by wget ---- echo $Result echo ' ' echo ---- Contents of wget log ---- cat $Logelif [[ -s $Document ]]then awk -f $Directory/mail-receive-status.awk $Document > $StatusLog if [[ -s $StatusLog ]] then cat $StatusLog echo -------------------- cat $Document fielif [[ -e $Document ]]then echo CiviCRM returned an empty result echo ' ' echo ---- Contents of wget log ---- cat $Logelse echo CiviCRM did not return a result echo ' ' echo ---- Contents of wget log ---- cat $Logfirm -f $Document $Log $StatusLog
#!/usr/bin/awk## Awk script to interpret the results of a CiviMail receipt## Here is a sample file that should be validated by this script ...# # REFERENCE : CONTENTS# ..........:............# 1 : connecting to yyy.zzz, authenticating as xxx@yyy.zzz and selecting INBOX# 2 : mailboxes found: INBOX.CiviMail.processed, INBOX.CiviMail.ignored, INBOX.Processed subscriptions, INBOX.Trash, INBOX.Sent, INBOX.Drafts, INBOX.Junk, INBOX.Processed replies, INBOX.Processed bounces, INBOX# 3{1} : fetching 50 messages# 3{1}.1[1] : retrieving message 2464# 3{1}.1[2] : retrieving message 2465# 3{1}.2[1] : setting 2464 as seen and moving it to the processed mailbox# 3{1}.2[2] : setting 2465 as seen and moving it to the processed mailbox# 4 : got to the end of the mailbox## To understand the reference column ...# * the numbers indicate sequence, # * '.' indicates a component of a larger structure,# * '[]' indicates repetition one or more times, and# * '{}' indicates repetition zero or more times## This script produces an empty file if the input file is valid.# Otherwise it produces a non-empty file explaining the problem## Specific problems that are targeted ...# * Missing line-reference 1, 2, or 4# * Mail sent to the 'ignored' mailbox on line-reference 3[].2[]# * Invalid content on any line## Program states, and state transitions ...## STATE : AFTER SEEING ... : VALID NEXT STATES : VALID PREVIOUS STATES# ......:....................:...................:......................# 1 : BEGIN : 2 : -# 2 : connecting to : 3 : 1# 3 : mailboxes found : 4, 7 : 2# 4 : fetching messages : 5 : 3, 6# 5 : retrieving message : 5, 6 : 4, 5# 6 : setting as seen : 4, 6, 7 : 5, 6# 7 : got to end : 8 : 3, 6# 8 : END : - : 7BEGIN { state = 1; processed = 0; }/^connecting to [a-z.-]+, authenticating as [a-z.@-]+ and selecting [A-Za-z]+$/ { if (state != 1) print "Line", NR, "-", "Unexpected 'connecting' message"; state = 2; processed++; }/^mailboxes found: .+$/ { if (state != 2) print "Line", NR, "-", "Unexpected 'mailboxes found' message"; state = 3; processed++; }/^fetching [0-9]+ messages$/ { if (state != 3 && state != 6) print "Line", NR, "-", "Unexpected 'fetching' message"; state = 4; processed++; }/^retrieving message [0-9]+$/ { if (state != 4 && state != 5) print "Line", NR, "-", "Unexpected 'retrieving' message"; state = 5; processed++; }/^setting [0-9]+ as seen and moving it to the processed mailbox$/ { if (state != 5 && state != 6) print "Line", NR, "-", "Unexpected 'setting' message"; state = 6; processed++; }/^setting [0-9]+ as seen and moving it to the ignored mailbox$/ { if (state != 5 && state != 6) print "Line", NR, "-", "Unexpected 'setting' message"; state = 6; print "Line", NR, "-", "Message ignored by CiviMail"; processed++; }/^got to the end of the mailbox$/ { if (state != 3 && state != 6) print "Line", NR, "-", "Unexpected 'got to end' message"; state = 7; processed++; }/^$/ { # Ignore blank lines processed++; }/^.+$/ { # Report unexpected non-blank lines if (NR != processed) { print "Line", NR, "-", "Unexpected line:", $0 processed++; } }END { if (state != 7) print "After line", NR, "-", "Unexpected end-of-file. Expected 'got to end of mailbox' message" }
connecting to smtp.gmail.com, authenticating as email@example.com and selecting INBOXmailboxes found: Follow up, INBOX, INBOX/CiviMail/ignored, INBOX/CiviMail/processed, Misc, Priority, [Gmail]/All Mail, [Gmail]/Drafts, [Gmail]/Sent Mail, [Gmail]/Spam, [Gmail]/Starred, [Gmail]/Trashgot to the end of the mailbox--------------------connecting to smtp.gmail.com, authenticating as email@example.com and selecting INBOXmailboxes found: Follow up, INBOX, INBOX/CiviMail/ignored, INBOX/CiviMail/processed, Misc, Priority, [Gmail]/All Mail, [Gmail]/Drafts, [Gmail]/Sent Mail, [Gmail]/Spam, [Gmail]/Starred, [Gmail]/Trashgot to the end of the mailbox
elif [[ -s $Document ]]then awk -f $Directory/mail-receive-status.awk $Document > $StatusLog if [[ -s $StatusLog ]] then cat $StatusLog echo -------------------- cat $Document fi
connecting to yyy.zzz, authenticating as xxx@yyy.zzz and selecting INBOXmailboxes found: INBOX.CiviMail.processed, INBOX.CiviMail.ignored, INBOX.Processed subscriptions, INBOX.Trash, INBOX.Sent, INBOX.Drafts, INBOX.Junk, INBOX.Processed replies, INBOX.Processed bounces, INBOXfetching 50 messagesretrieving message 2464retrieving message 2465setting 2464 as seen and moving it to the processed mailboxsetting 2465 as seen and moving it to the processed mailboxgot to the end of the mailbox
awk -f mail-receive-status.awk mail-receive-test.txt
connecting to yyy.zzz, authenticating as xxx@yyy.zzz and selecting INBOXmailboxes found: INBOX.CiviMail.processed, INBOX.CiviMail.ignored, INBOX.Processed subscriptions, INBOX.Trash, INBOX.Sent, INBOX.Drafts, INBOX.Junk, INBOX.Processed replies, INBOX.Processed bounces, INBOXfetching 50 messagesgobledy-goop, it makes no senseretrieving message 2464retrieving message 2465setting 2464 as seen and moving it to the processed mailboxsetting 2465 as seen and moving it to the processed mailboxgot to the end of the mailbox
connecting to yyy.zzz, authenticating as xxx@yyy.zzz and selecting INBOXmailboxes found: INBOX.CiviMail.processed, INBOX.CiviMail.ignored, INBOX.Processed subscriptions, INBOX.Trash, INBOX.Sent, INBOX.Drafts, INBOX.Junk, INBOX.Processed replies, INBOX.Processed bounces, INBOXfetching 50 messagesgobledy-goop, it makes no senseLine 4 - Unexpected line: gobledy-goop, it makes no senseretrieving message 2464retrieving message 2465setting 2464 as seen and moving it to the processed mailboxsetting 2465 as seen and moving it to the processed mailboxgot to the end of the mailbox