无法从Apache httpd调用Shell脚本 [英] Unable to call shell script from apache httpd

查看:328
本文介绍了无法从Apache httpd调用Shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从/etc/httpd/sites-available中的000-default.conf调用Shell脚本.

I am trying to call shell script from 000-default.conf inside /etc/httpd/sites-available.

000-default.conf文件的内容为:

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>

我的/etc/httpd/conf/httpd.conf中添加了以下内容:

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

我在/var/www/html/中保留了一个虚拟html文件 index.html的内容:

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>

每当我点击 http://localhost:80 时,根本不会调用shell脚本.该shell脚本是可执行文件,它只显示"Hello World".

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".

但是当我从000-default.conf文件中调用apache kafka二进制文件时,它将正常工作.

But when I call apache kafka binary from 000-default.conf file then it works properly.

修改后的000-default.conf文件:

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>

现在,当我单击 http://localhost:80 时,消息将在远程kafka服务器中发送.

Now when I click on http://localhost:80 then message is send in remote kafka server.

这里有人可以帮我如何从apache httpd调用shell脚本吗?

Can any one help here how can I call shell script from apache httpd?

推荐答案

这是send_message.sh的内容:

Here is the content of send_message.sh:

#! /bin/sh


PRIVATE_KEY=$1
HOST=$2
TOPIC_NAME=$3
MESSAGE=$4

echo "OCI VM IP : $HOST"
echo "PRIVATE KEY : $PRIVATE_KEY"
echo "TOPIC-NAME: $TOPIC_NAME"
echo "MESSAGE: $MESSAGE"

## Run Cmd in vm
ssh -o "StrictHostKeyChecking no" -i $PRIVATE_KEY opc@$HOST /bin/bash << EOF
       sudo su
       echo $MESSAGE | [HOME_DIR]/bin/kafka-console-producer.sh --broker-list [VM_IP]:9092 --topic $TOPIC_NAME
EOF 

/etc/httpd/sites-available/000-dafult.conf的内容

And content of /etc/httpd/sites-available/000-dafult.conf

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /var/www/html/
    CustomLog "| /home/opc/send_message.sh /home/opc/dev2oci.key 100.111.69.61 access-log apache-httpd" custom_user_tracking
</VirtualHost>

每5s间隔将消息发送到topi access_log中.尽管 http://localhost:80 并不是从浏览器触发的.

The message is sent in topi access_log for every 5s interval. Though the http://localhost:80 is not triggered from browser.

如果我用以下条目替换CustomLog:

If I replace the CustomLog with below entry:

CustomLog "| [HOME_DIR]/bin/kafka-console-producer.sh --topic access-log --broker-list [VM_IP]:9092" custom_user_tracking

然后在浏览器触发 http://localhost:80 时发送消息.

Then message is sent on triggering http://localhost:80 from browser.

有人可以让我知道我在这里想念的东西吗.

Can anyone let me know what I am missing here.

这篇关于无法从Apache httpd调用Shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆