I am trying to call shell script from 000-default.conf inside /etc/httpd/sites-available.
The 000-default.conf file content is :
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/html/
CustomLog "| sh /scratch/user/test.sh" custom_user_tracking
</VirtualHost>
My /etc/httpd/conf/httpd.conf has below content added:
ServerName localhost
LogFormat "%t [%h] [%m] [%U] [%B] [%b] [%D] [%q] [%s] [%{Referer}i] [%{User-Agent}i]" custom_user_tracking
IncludeOptional sites-enabled/*.conf
IncludeOptional sites-available/*.conf
I have kept a dummy html file inside /var/www/html/
Content of index.html:
<!DOCTYPE html>
<html>
<body>
<h1>Hello World!</h1>
</body>
</html>
When ever I hit http://localhost:80 the shell script is not called at all. The shell script is executable and it just prints “Hello World”.
But when I call apache kafka binary from 000-default.conf file then it works properly.
Modified 000-default.conf file:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/html/
CustomLog "| [HOME_DIR_KAFKA]/bin/kafka-console-producer.sh --topic access-log --broker- list <Remote_host_ip>:9092" custom_user_tracking
</VirtualHost>
Now when I click on http://localhost:80 then message is send in remote kafka server.
Can any one help here how can I call shell script from apache httpd?
2
Answers
Here is the content of send_message.sh:
And content of /etc/httpd/sites-available/000-dafult.conf
The message is sent in topi access_log for every 5s interval. Though the http://localhost:80 is not triggered from browser.
If I replace the CustomLog with below entry:
Then message is sent on triggering http://localhost:80 from browser.
Can anyone let me know what I am missing here.
Consider making the test.sh script executable using “shebang” ($!), instead of using sh.
Alternatively run ‘sh’ using full path
CustomLog “| /bin/sh /scratch/user/test.sh” custom_user_tracking
Also, double check the execute permission on /scratch/user/test.sh, and the permission on the folder. https is usually running as non-privileged account.