4.9. Scripting RT

 < Day Day Up > 

Sometimes the CLI can be overly verbose or confusing, with the many options and commands available. One way to make the interaction a bit simpler is to use your shell to simplify common operations.

4.9.1. Shell Functions

If you're using a Bourne-like shell (bash, ksh, /bin/sh on most systems), you can create shell functions by placing the following in your .profile:

     rtspam(  ) {       rt edit ticket/$1 set queue=spam status=deleted     }           rtresolve(  ) {       rt edit ticket/$1 set status=resolved     }           rtshow(  ) {       rt show ticket/$1     } 

Now to use these functions directly from your shell:

     $ rtresolve 12345     Ticket 12345 Resolved. 

You could do this just as well with shell scripts, but shell functions are more elegant.

4.9.2. Shell Aliases

An alternative to dedicating a function to the task would be to do the same thing but use an alias instead. In a Bourne-like shell (bash, ksh, sh, etc.), alias commands like these may be useful in your .profile:

     alias rtspam='rt edit ticket/$1 set queue=spam status=deleted'        alias rttop='rt ls -i "priority > 70 and status != resolved" | rt show - -f id,subject' 

If you're using a C shell (csh or tcsh), try these in your .cshrc:

     alias rtspam 'rt edit ticket/\!:1 set queue=spam status=deleted'           alias rtresolve 'rt edit ticket/\!:1 set status=resolved'           alias rtshow 'rt show ticket/\!:1' 

4.9.3. MIME

One useful tidbit if you're scripting RT from Perl is that the output of rt show is a valid MIME object. Modules like MIME::Parser or Email::Simple can parse it and manipulate it further:

     use Email::Simple;           my $tno = $ARGV[0];     my $ticket = `rt show ticket/$tno`;     my $tobj = Email::Simple->new($ticket);           print "Ticket $tno was requested by ", $tobj->header("requestors"),           " on ", $tobj->header("created"), ".\n"; 

     < Day Day Up > 


    RT Essentials
    RT Essentials
    ISBN: 0596006683
    EAN: 2147483647
    Year: 2005
    Pages: 166

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net