如何调用从Web服务器的本地shell脚本? [英] How do I call a local shell script from a web server?

查看:1644
本文介绍了如何调用从Web服务器的本地shell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行Ubuntu 11,我想建立一个简单的网络服务器,通过调用带有GET或POST参数的本地脚本响应HTTP请求。这个脚本(已书面)做一些事情,并创建一个文件。该文件应提供在URL,然后Web服务器应该让一个HTTP请求到另一台服务器,告诉它来下载创建的文件。

I am running Ubuntu 11 and I would like to setup a simple webserver that responds to an http request by calling a local script with the GET or POST parameters. This script (already written) does some stuff and creates a file. This file should be made available at a URL, and the webserver should then make an http request to another server telling it to download the created file.

我将如何去设置这个吗?我不是Linux的总初学者,但我不会说我知道它太好。

How would I go about setting this up? I'm not a total beginner with linux, but I wouldn't say I know it well either.

什么web服务器?如何我授权脚本访问本地资源,创造有问题的文件?我不是太关心安全或任何东西,这是一个个人的实验(我有超过所涉及的所有计算机控制)。我以前用过的Apache,但我从来没有设置。

What webserver should I use? How do I give permission for the script to access local resources to create the file in question? I'm not too concerned with security or anything, this is for a personal experiment (I have control over all the computers involved). I've used apache before, but I've never set it up.

任何帮助将是AP preciated ..

Any help would be appreciated..

推荐答案

本教程看起来不错,但它是一个有点短。

This tutorial looks good, but it's a bit brief.

我已经Apache的安装。如果不这样做: sudo易于得到安装的Apache2

I have apache installed. If you don't: sudo apt-get install apache2.

cd /usr/lib/cgi-bin

# Make a file and let everyone execute it
sudo touch test.sh && chmod a+x test.sh 

然后把一些code的文件中。例如:

Then put the some code in the file. For example:

#!/bin/bash
# get today's date
OUTPUT="$(date)"
# You must add following two lines before
# outputting data to the web browser from shell
# script
 echo "Content-type: text/html"
 echo ""
 echo "<html><head><title>Demo</title></head><body>"
 echo "Today is $OUTPUT <br>"
 echo "Current directory is $(pwd) <br>"
 echo "Shell Script name is $0"
 echo "</body></html>"

最后打开浏览器,输入的http://localhost/cgi-bin/test.sh

如果一切顺利的话(因为它为我做的),你应该看到...

If all goes well (as it did for me) you should see...

今天是Sun 12月4日...结果
  当前目录是/ usr / lib目录/ cgi-bin目录壳牌结果
  Shell脚本的名字是/usr/lib/cgi-bin/test.sh

Today is Sun Dec 4 ...
Current directory is /usr/lib/cgi-bin Shell
Shell Script name is /usr/lib/cgi-bin/test.sh

这篇关于如何调用从Web服务器的本地shell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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