not getting execute shell script from GenericAgent CMD

Moderator: crythias

Post Reply
ashwinigore
Znuny newbie
Posts: 26
Joined: 27 Apr 2020, 14:28
Znuny Version: 6.0.27
Real Name: Ashwini Gore
Company: Alepo

not getting execute shell script from GenericAgent CMD

Post by ashwinigore »

Requirement : I want to call some command line program when any ticket is generated.
So created one shell script. I am new to OTRS. Please guide if I can use any other feature to call some external shell/perl/python script on specific operation like create or update ticket

guys I am unable to execute external script using generic agent - OTRS
6.0.27 version

1. able to run samplecommandlineprog.sh using otrs user
2. it is just hello world kind of one liner script
3. permission are as follows -

[otrs@localhost GenericAgent]$ ls -lrth /tmp/sample.log
-rwxrw-rw-. 1 otrs apache 0 Apr 28 20:05 /tmp/sample.log

[otrs@localhost GenericAgent]$ ls -lrth samplecommandlineprog.sh
-rwxr-xr-x. 1 otrs apache 74 Apr 28 20:06 samplecommandlineprog.sh


4. I am getting below error when i do run this job in tail -f /var/log/httpd/error_log

[Tue Apr 28 20:06:45 2020] -e: Reference found where even-sized list expected at /opt/otrs//Kernel/System/GenericAgent.pm line 988.


5. generic agent interface
CMD = /bin/bash /opt/otrs/scripts/test/sample/GenericAgent/samplecommandlineprog.sh
Last edited by ashwinigore on 28 Apr 2020, 16:39, edited 1 time in total.
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: not getting execute shell script from GenericAgent CMD

Post by RStraub »

Well you have a syntax error in the file, as reported by the log... Mind showing the module ?
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
ashwinigore
Znuny newbie
Posts: 26
Joined: 27 Apr 2020, 14:28
Znuny Version: 6.0.27
Real Name: Ashwini Gore
Company: Alepo

Re: not getting execute shell script from GenericAgent CMD

Post by ashwinigore »

it is working from command line with otrs user, i don't see any issue shell script.
[otrs@localhost GenericAgent]$ cat samplecommandlineprog.sh
#! /bin/bash
echo "OTRS test" >> /tmp/sample.log
date >> /tmp/sample.log

[otrs@localhost GenericAgent]$ /bin/bash /opt/otrs/scripts/test/sample/GenericAgent/samplecommandlineprog.sh
[otrs@localhost GenericAgent]$ cat /tmp/sample.log
OTRS test
Tue Apr 28 20:40:06 IST 2020
[otrs@localhost GenericAgent]$



i haven't touch /opt/otrs//Kernel/System/GenericAgent.pm, it is default installation
ashwinigore
Znuny newbie
Posts: 26
Joined: 27 Apr 2020, 14:28
Znuny Version: 6.0.27
Real Name: Ashwini Gore
Company: Alepo

Re: not getting execute shell script from GenericAgent CMD

Post by ashwinigore »

it is working from command line with otrs user, i don't see any issue shell script.
[otrs@localhost GenericAgent]$ cat samplecommandlineprog.sh
#! /bin/bash
echo "OTRS test" >> /tmp/sample.log
date >> /tmp/sample.log

[otrs@localhost GenericAgent]$ /bin/bash /opt/otrs/scripts/test/sample/GenericAgent/samplecommandlineprog.sh
[otrs@localhost GenericAgent]$ cat /tmp/sample.log
OTRS test
Tue Apr 28 20:40:06 IST 2020
[otrs@localhost GenericAgent]$



i haven't touch /opt/otrs//Kernel/System/GenericAgent.pm, it is default installation
ashwinigore
Znuny newbie
Posts: 26
Joined: 27 Apr 2020, 14:28
Znuny Version: 6.0.27
Real Name: Ashwini Gore
Company: Alepo

Re: not getting execute shell script from GenericAgent CMD

Post by ashwinigore »

when i removed "add note" section, below error is not noticed in /var/log/httpd/error_log file


but my script is also not got executed, as i can't see any new logwrite in /tmp/sample.log file

access_log received as follows -
172.16.105.32 - - [28/Apr/2020:20:44:48 +0530] "GET /otrs/index.pl?Action=AdminGenericAgent;Subaction=RunNow;Profile=Sample%20Commandline%20Program%20Execute;ChallengeToken=ZWYaU9so5SenJWpk93NCRlp3bj6mdFww; HTTP/1.1" 302 69 "http://172.16.111.125/otrs/index.pl?Act ... p3bj6mdFww;" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36"
172.16.105.32 - - [28/Apr/2020:20:44:48 +0530] "GET /otrs/index.pl?Action=AdminGenericAgent HTTP/1.1" 200 6376 "http://172.16.111.125/otrs/index.pl?Act ... p3bj6mdFww;" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36"
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: not getting execute shell script from GenericAgent CMD

Post by RStraub »

I think to remember there was another post where the conclusion was you cannot run a CMD from the generic agent with two arguments.

The solution was to make your bash script executable and put it into the home of OTRS, then only call the script without "/bin/bash"
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
zzz
Znuny superhero
Posts: 888
Joined: 15 Dec 2016, 15:13
Znuny Version: All
Real Name: Emin
Company: Efflux GmbH
Contact:

Re: not getting execute shell script from GenericAgent CMD

Post by zzz »

Hey,

This topic should show a working way to execute a shell script from a generic agent (with all its quirks and features).
viewtopic.php?f=53&t=41459&p=167423#p167423

— Emin
Professional OTRS, Znuny & OTOBO services: efflux.de | efflux.de/en/

Free and premium add-ons: German | English
ashwinigore
Znuny newbie
Posts: 26
Joined: 27 Apr 2020, 14:28
Znuny Version: 6.0.27
Real Name: Ashwini Gore
Company: Alepo

Re: not getting execute shell script from GenericAgent CMD

Post by ashwinigore »

thanks for ur reply. I copy script at /opt/otrs i.e. otrs home directory.

CMD = /opt/otrs/samplecommandlineprog.sh configured in GenericAgent
When i am running the job, no error noticed in /var/log/httpd/error_log
But it not writing anything in my log file. If I give wrong path in CMD then i can see file not found. Means GericAgent is trying to execute the script but not findings.

What to do???? my script is not getting executed? Is there any way to identify if script is getting execute or not?

[otrs@localhost otrs]$ ls -lrth samplecommandlineprog.sh
-rwxrwx--x. 1 otrs apache 97 Apr 30 12:36 samplecommandlineprog.sh

[otrs@localhost otrs]$ ls -lrth /tmp/sample.log
-rwxrw-rw-. 1 otrs apache 234 Apr 30 12:44 /tmp/sample.log
[otrs@localhost otrs]$


[otrs@localhost otrs]$

[otrs@localhost otrs]$ pwd
/opt/otrs
[otrs@localhost otrs]$ cat samplecommandlineprog.sh
#! /bin/bash
touch /tmp/newfile.log
echo "OTRS test" >> /tmp/sample.log
date >> /tmp/sample.log
zzz
Znuny superhero
Posts: 888
Joined: 15 Dec 2016, 15:13
Znuny Version: All
Real Name: Emin
Company: Efflux GmbH
Contact:

Re: not getting execute shell script from GenericAgent CMD

Post by zzz »

Oh, I just saw that you already made a post on that topic.

Get sure that the otrs user is able to execute the script. Switch to the otrs user and run it by hand.
The generic agent needs to be executed; that means you need to have at least one hit.
If you have multiple hits, the script will get executed multiple times.

You're trying to write to /tmp/. Try /opt/otrs/ first before switching to another patch.

— Emin
Professional OTRS, Znuny & OTOBO services: efflux.de | efflux.de/en/

Free and premium add-ons: German | English
ashwinigore
Znuny newbie
Posts: 26
Joined: 27 Apr 2020, 14:28
Znuny Version: 6.0.27
Real Name: Ashwini Gore
Company: Alepo

Re: not getting execute shell script from GenericAgent CMD

Post by ashwinigore »

1. Attempt one to execute from otrs user, command line. successful

[root@localhost ~]# su - otrs
Last login: Thu Apr 30 15:37:56 IST 2020 on pts/2
[otrs@localhost ~]$
[otrs@localhost ~]$
[otrs@localhost ~]$
[otrs@localhost ~]$ pwd
/opt/otrs/
[otrs@localhost ~]$ /opt/otrs/samplecommandlineprog.sh
[otrs@localhost ~]$ date
Sat May 2 19:33:37 IST 2020
[otrs@localhost ~]$ tail -f /tmp/sample.log
OTRS test
Thu Apr 30 11:27:52 IST 2020
OTRS test
Thu Apr 30 12:42:20 IST 2020
OTRS test
Thu Apr 30 12:44:29 IST 2020
OTRS test
Thu Apr 30 12:44:41 IST 2020
OTRS test
Sat May 2 19:33:33 IST 2020





2. Attempt two changling logfile path to OTRSHOME, successful

[otrs@localhost ~]$ cat /opt/otrs/samplecommandlineprog.sh
#! /bin/bash
touch /opt/otrs/newfile.log
echo "OTRS test" >> /opt/otrs/sample.log
date >> /opt/otrs/sample.log

[otrs@localhost ~]$ date
Sat May 2 19:36:28 IST 2020
[otrs@localhost ~]$ /opt/otrs/samplecommandlineprog.sh
[otrs@localhost ~]$ tail -f /opt/otrs/sample.log
OTRS test
Sat May 2 19:36:41 IST 2020



3. attempt 3 from GenericAgent, RunJob option.10 tickets qualifying for defined criteria. Restarted HTTPD services. then it worked.
great. thanks for help. Its not require to configure
Post Reply