- Setup your .rtrc and .bashrc as a one-off so you can invoke the RT CLI directly
- Build a search query in the regular RT Web UI
- Automate the function
Add it to your PATH in .bashrc:[support-email@rt ~]$ locate */rt/opt/rt4/bin/rt
Setup your .rtrc file with your credentials rather than giving them on the command line:export PATH=$PATH:/opt/rt4/bin
Now you can already do some stuff like the examples from the RT CLI page in the wiki:[support-email@rt ~]$ cat .rtrcserver http://rt/user mepasswd xxxauth rt
The last "prep" thing is to create your search criteria. This is far easier in the Web UI like you can build up your Search and then when you click Advanced you can copy that Query text directly and test it out from the CLI:[support-email@rt ~]$ rt show user/ggeeid: user/832782Password: ********Name: GGeeEmailAddress: GGee@example.comRealName: G GeePrivileged: 1Disabled: 0CF-Employee Department: Applications Software
Now you're ready for some automation.[support-email@rt ~]$ rt ls -i -q "'Corp Support'" "Status = 'stalled' AND Told < '-1 week'"ticket/314370ticket/315571
- The use of "-i" gives the output in a suitable format for processing
- The "-q" option specifies a queue and you need to use quotes (') around names with spaces in them, hence on the CLI you get "'Corp Support'"
The above query is Searching for Stalled tickets which haven't been touched (Told) in over a week. We want to change such tickets to Open so that staff pick up these tickets. For this we can setup a job with cron which pipes the tickets found in a search into an rt edit command.
# un-stalls support tickets NOTE: requires valid creds in .rtrc
@daily /opt/rt4/bin/rt ls -i -q "'Corp Support'" "Status = 'stalled' AND Told < '-1 week'" | rt edit - set status=openYou can automate all kinds of functionality whether routine activities like this example, or to build helper scripts for large operations like to populate some new custom field or otherwise.