[rt-users] rt v. rt-crontool

Yan Seiner yan at seiner.com
Wed Nov 23 14:06:12 EST 2011


The recent discussion on modifying custom fields got me thinking.... What
is the difference between using rt and rt-crontool?

Seems that both can do slightly different things and are really different
tools.  The name makes it seem like rt-crontool is somehow preferred when
running a scheduled job, but I can't think of a reason why rt could not be
used in a cron job.

Here's a script I use to create a linked ticket from an email:

#!/bin/bash

# exim helper script for adding an invoice ticket to a work order

# create a temp file and dump stdio into it
t=$(tempfile --directory=/tmp) || exit 1
cat - > $t

# we create the ticket
subject=$(grep -i '^subject:' $t | sed -e 's/^.*: *//')
ticket=$(/opt/rt4/bin/rt create -t ticket set queue="Water Invoices"
subject="${subject}" | sed -e s/[^0-9]//g)
parent=$(/opt/rt4/bin/rt ls -i "'CF.{Work Order No.}'=${LOCAL_PART} and
queue!='Water Invoices'" | sed -e s+^.*/++)

# validate $parent here; exit 1 if not found
if [[ -z $parent ]] ; then
    echo "Work Order ${LOCAL_PART} not found"
    exit 1
fi

# exit 1 if multiple tickets found
if [ `echo $parent | wc | awk '{print $2}'` -gt 1 ] ; then
    echo "Multiple tickets with Work Order ${LOCAL_PART} found"
    echo "ticket numbers are " `echo $parent | sed s+ticket/++g`
    exit 1
fi

# Now link ticket
/opt/rt4/bin/rt link ${ticket} memberof ${parent}

# and set custom fields
/opt/rt4/bin/rt edit ticket/${ticket} set 'CF.{contractor}'="${contractor}"
/opt/rt4/bin/rt edit ticket/${ticket} set 'CF.{amount}'="${amount}"

export EXTENSION=${ticket}
cat $t | /opt/rt4/bin/rt-mailgate --action comment --queue Invoices
--extension ticket --url http://rt.subutil.com


-- 
Pain is temporary. It may last a minute, or an hour, or a day, or a year,
but eventually it will subside and something else will take its place. If
I quit, however, it lasts forever.




More information about the rt-users mailing list