My AGI is not executing some commands

Hi,

I wrote a simple perl script which is used to append messages on a log file, as listed below;

#!/usr/bin/perl
use strict;
use Asterisk::AGI;
use warnings;

my $agi = new Asterisk::AGI;

print “Sending Message is under progress!!!\n”;
$agi->verbose(“Sending Message is under progress!!!\n”,1);

my $start_local=localtime();
system(“printf =======================’\n’ >> log”);
system("printf "START TIME: $start_local “’\n’ >> log”);
system(“printf =======================’\n’ >> log”);

exit();

When I tried to run this script by perl, it appends the text to a log file and when I tried to run it via AGI, it don’t write anything on log file. I’m calling this perl script from dialplan i.e.

exten => pager,1,NoOp(Request came in)
exten => pager,n,AGI(test.pl)
exten => pager,n,HangUp()

Please advice at earliest.

What directory is Asterisk running in?

I would just give an absolute path name.

Sorry forgot to mention, the path I defined to call perl script located in my home directory i.e.

exten => pager,n,AGI(/home/abc/test.pl)

Even I gave absolute path but getting same response.

Are you running Asterisk non-root?

Is the script marked executable? Does it work if you run it at a shell prompt without prefixing it with “perl”?

change the script permission by chmod 777 and try.

And paste your asterisk console log here to understand what the issue you are facing.

Please don’t advise changing permissions to 777. Writeable scripts are a security risk. The most that is needed is

chmod =rx script

Forgot to inform you earlier, I made that script executable. Even I run this script ./test.pl either as a root or other user i.e. abc user, the script is able to print the lines in a log file but still unable to print the lines if I call it from asterisk.

The asterisk is running not as a root but as a user asterisk.

Please advice.

Permission problem on log file.

The permission for log file I set is chmod 666 but the problem remains the same.

SELINUX settings and directory permissions.

Note it is generally much less hassle to run Asterisk as root, and if you don’t you should not be opening permissions wide when you hit a problem, you should be understanding the problem.

David, thanks for a good advice. Now issue has been resolved.