Executing bash script OTRS 5

Moderator: crythias

Post Reply
acarrilloj
Znuny newbie
Posts: 3
Joined: 26 Jun 2017, 16:07
Znuny Version: 5.0.1.0.0
Real Name: Albert
Company: None

Executing bash script OTRS 5

Post by acarrilloj »

Hi all,

First, thanks to help me in advanced, and sorry because I'm new on OTRS :)

On my OTRS I have a queue for important issues.
I need to execute a bash script on the server (same where is OTRS) when a new ticket arrives on that queue.

I've been looking around and searching and no solution works for me.

On GenericAgent, I've tried to run it on CMD, but nothing happens.

Could you give me any clue?

Thanks so much!! :)
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Executing bash script OTRS 5

Post by RStraub »

Hey there,

that shouldn't be too hard.

I just tested like so:
1) Create a file in /opt/otrs/otterhub_test.sh
and write into it:

Code: Select all

#!/bin/bash

touch /tmp/otterhub_test
then make it executable.

2) Create a generic agent, filter on a hardcoded ticketnumber (just use one that exists, so that the GA actually runs) and put into the ticket command input field:

Code: Select all

/opt/otrs/otterhub_test.sh
After running the generic agent, you should have a new file in /tmp/ called otterhub_test.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
acarrilloj
Znuny newbie
Posts: 3
Joined: 26 Jun 2017, 16:07
Znuny Version: 5.0.1.0.0
Real Name: Albert
Company: None

Re: Executing bash script OTRS 5

Post by acarrilloj »

OH! I was trying with /bin/bash /root/script.sh

It worcks!! thanks so much!! :)
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Executing bash script OTRS 5

Post by RStraub »

Very welcome. In that script if you use "$1", the first parameter should hold the ticket id of the current processed ticket.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
pisoir
Znuny newbie
Posts: 7
Joined: 03 Jul 2017, 21:11
Znuny Version: 5.0.15

Re: Executing bash script OTRS 5

Post by pisoir »

Dear RSstraub,

I have the same problem. When I copied everything what you wrote, it indeed saved the file somewhere in the /tmp/ (although not directly in /tmp/ but to a temporary subfolder something like /tmp/systemd-private-0e234xxxxxx-httpd.service-2mCasd/tmp ). However, I would like to save the file into my /home/ directory. When I change the path in the script, nothing is saved.

The script is chmod 777 and executable. I also tried to change the file owner from "root" to "otrs" but the file is never saved. I am running Centos7. Can it be that some safety measures of the Centos are blocking the saving? What do I need to change such that the file is created in my home directory?

btw. when I run the script manually, everything works fine. Only when run from OTRS Generic Agent, nothing works.

Any help is appreciated.
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Executing bash script OTRS 5

Post by RStraub »

Are you using absolute paths when accessing "home" or are you using the tilde? Those cannot be used when you are running a script from a non-login shell.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
pisoir
Znuny newbie
Posts: 7
Joined: 03 Jul 2017, 21:11
Znuny Version: 5.0.15

Re: Executing bash script OTRS 5

Post by pisoir »

I am using absolute path i.e.
touch /home/test.txt

but I just tried also with ~/test.txt but seems none of it works. But when I run the script from command line everything works.
pisoir
Znuny newbie
Posts: 7
Joined: 03 Jul 2017, 21:11
Znuny Version: 5.0.15

Re: Executing bash script OTRS 5

Post by pisoir »

I am starting to believe that it is indeed some safety measure of Centos7:
https://stackoverflow.com/questions/107 ... edir-value

that would explain why I can't write to /tmp/. Unfortunately I still haven't managed to get it running.
Post Reply