Execute bash script when creating new ticket

I have been trying to figure out a way to call a bash script every time a new ticket is created. I was just wondering if this is possible and if it would be tricky to do. The script does not need anything to be passed along with it, it just needs to be run every time a new ticket is created

I think you can create a custom RT scrip:

Condition: “On Create”
Action: “User Defined”

Then for the user defined condition since it is Perl code you can use backticks to execute sh commands:


I tried this and it didn’t work, though I’m not sure I’m doing it right. This is what I have right now

Condition: “On Create”
Action: “User Defined”
Custom Condition: blank
Custom action preparation code: blank
Custom action commit code: ./some_script.sh
(edit: there are backticks on ./some_script.sh but they aren’t showing up here)

I’m not familiar with scrips in rt yet, do I need other code in the custom condition or custom action preparation code in order for this to work?

You want to return true for the action prep code:

return 1;

You might also want a full path to the script - say something like /usr/local/bin/some_script.sh. And you’ll need that script visible and executable by the user that your web server runs under (usually something like apache or www-server or www-daemon depending on your operating system).

Thanks for the responses guys I really appreciate it. Yeah I have the full path to the file in the backticks and I gave execute permissions to apache(what is in use on our rt) for that file. For some reason it still doesn’t seem to be executing. Any ideas on what could still be stopping it?

Can you check the rt log for whether or not the scrip succeeded? You can also output some logging from your bash script somewhere to check

Launching scripts and accessing temporary files and network connections from web servers can sometimes be stymied by things like SELinux and systemd. If you have SELinux turned on, try either looking in the audit log or (very temporarily) turning it into permissive mode and seeing if the script then works. Also check if the web server logs anything - sometimes you see “Permission denied” errors.

Ok I checked and I know the scrip succeeded. In the scrip I write to a text file(using perl), then call a shell script that writes to the same text file and at the end of the file I write to the text file using perl again. Here is the contents of my Custom action commit code:

my $filename = '/my/text/file.txt';
my $str = "START OF SCRIP\n";

open(FH, '>>', $filename) or die $!;

print FH $str;


my $command = "/bin/sh /some/script.sh";

$filename = '/my/text/file/test.txt';
$str = "END OF SCRIP\n";

open(FH, '>>', $filename) or die $!;

print FH $str;


My text file only ends up containing “START OF SCRIP” and “END OF SCRIP” even though /some/script.sh writes to the same file. If I run this chunk of code through perl in the console(running it on my own and not waiting to it to be triggered by RT) it works exactly as expected. So the code is correct, but there is something that is blocking RT from calling /some/script.sh. Just wondering if this information helps figure out what is wrong. The permissions are definitely correct. Thanks for the help!

Is the text file in /tmp by any chance? Some distributions set up Apache so that, by default, it writes to a private temporary directory. Your scrip may well end up writing there as well but the shell script might try to write somewhere else. Also rather than having the system() call process a single string (which creates another shell in which to execute the string), try system("/bin/sh", "/some/script.sh");. It may be that the user your web server is running under has a default shell of something like /bin/false.

The other thing to try is to to get the error from the system call. So something like:

system('/bin/sh', '/some/script.sh') == 0 or warn "system failed: $?";

That might give you more of a clue why it is failing.