/var/www/cgi-bin/hello.sh

#!/bin/bash

echo "Content-type: text/html"
echo ""

echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo '<title>Hello World</title>'
echo '</head>'
echo '<body>'
echo 'Hello World'
echo '</body>'
echo '</html>'

exit
        

赋予执行权限:

chmod +x /var/www/cgi-bin/hello.sh

如果使用SELinux,必须执行以下命令: chcon -t httpd_sys_content_t /var/www/cgi-bin/hello.sh

访问:

http://ip/cgi-bin/hello.sh

同理:

/var/www/cgi-bin/uptime.sh

#!/bin/bash

echo "Content-type: text/html"
echo ""

echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo '<link rel="SHORTCUT ICON" href="http://www.megacorp.com/favicon.ico">'
echo '<link rel="stylesheet" href="http://www.megacorp.com/style.css" type="text/css">'

PATH="/bin:/usr/bin:/usr/ucb:/usr/opt/bin"
export $PATH

echo '<title>System Uptime</title>'
echo '</head>'
echo '<body>'

echo '<h3>'
hostname
echo '</h3>'

uptime

echo '</body>'
echo '</html>'

exit 

http://192.168.1.112/cgi-bin/uptime.sh

/var/www/cgi-bin/env.sh

#!/bin/bash

echo "Content-type: text/html"
echo ""

echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo '<title>Environment Variables</title>'
echo '</head>'
echo '<body>'
echo 'Environment Variables:'
echo '<pre>'
/usr/bin/env
echo '</pre>'

echo '</body>'
echo '</html>'

exit
        

http://192.168.1.112/cgi-bin/env.sh?namex=valuex&namey=valuey&namez=valuez

参考:

http://www.yolinux.com/TUTORIALS/BashShellCgi.html

Linux环境下使用shell编写CGI(httpd)的更多相关文章

  1. Linux环境下使用perl编写CGI(httpd)

    例子1: /var/www/cgi-bin/hello.cgi #!/usr/bin/perl print "Content-type: text/html\n\n"; print ...

  2. [Apache手册]Linux环境下配置Apache运行cgi

    CGI动态页面 相关模块 相关指令 mod_alias mod_cgi AddHandler Options ScriptAlias CGI(公共网关接口)定义了web服务器与外部内容生成程序之间交互 ...

  3. PHP 命令行模式实战之cli+mysql 模拟队列批量发送邮件(在Linux环境下PHP 异步执行脚本发送事件通知消息实际案例)

    源码地址:https://github.com/Tinywan/PHP_Experience 测试环境配置: 环境:Windows 7系统 .PHP7.0.Apache服务器 PHP框架:ThinkP ...

  4. linux环境下的GUN make学习笔记(一)

    第一章:概述 1.1:make概述 在linux环境下使用make工具能够比较容易的构建一个属于自己的工程,整个工程的编译只需要一个命令就可以完成编译.连接以至于最后的执行.不过我们需要投入一些时间去 ...

  5. Linux 环境下安装python相关

    目录 Linux 环境下安装python相关 linux软件包管理工具之yum工具(如同pip3工具) yum源理解 下载阿里云的.repo仓库文件 ,放到/etc/yum.repos.d/ yum安 ...

  6. 在Linux环境下采用压缩包方式安装JDK 13

    本文地址:https://www.cnblogs.com/oberon-zjt0806/p/11663731.html 可以,转载,出处,格式,懂?? 什么是JDK?? 好吧如果你不知道这个问题的话我 ...

  7. 【环境配置】Linux环境下下载、配置java环境、安装eclipse、建立eclipse快捷方式详解

    一.首先是下载Java JDK 到目前为止的最新版本为(jdk1.8.0_60),有两种方式进行下载: 1.使用shell来进行下载,可使用如下命令直接进行下载: wget --no-check-ce ...

  8. 教你如何在Kali Linux 环境下设置蜜罐?

    导读 Pentbox是一个包含了许多可以使渗透测试工作变得简单流程化的工具的安全套件.它是用Ruby编写并且面向GNU/Linux,同时也支持Windows.MacOS和其它任何安装有Ruby的系统. ...

  9. linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg)

     linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg) 2013-11-10 16:51:14 分类: 系统运维 为什么要写这篇文章? 答:通过常规的三大步(./confi ...

随机推荐

  1. TO BE OPEN

    我们通常都在一个很狭隘的世界里. 却以为我们有了整个蓝天.

  2. js判断移动端是否安装某款app的多种方法

    本文实例讲解了js判断移动端是否安装某款app的多种方法,分享给大家供大家参考,具体内容如下 第一种方法: 一:判断是那种设备 ? || u.indexOf(; //android终端或者uc浏览器 ...

  3. 【GoLang】类型和作用在它上面定义的方法必须在同一个包里定义

    cannot define new methods on non-local type int 参考资料: http://wiki.jikexueyuan.com/project/the-way-to ...

  4. poj 1700

    http://poj.org/problem?id=1700 题目大意就是一条船,有N个人需要过河,求N个人最短过河的时间 #include <stdio.h> int main() { ...

  5. spinlock原理

    [参考] http://www.searchtb.com/2011/06/spinlock%E5%89%96%E6%9E%90%E4%B8%8E%E6%94%B9%E8%BF%9B.html

  6. jquery checkbox 限制多选的个数

    2015年11月6日 16:32:49 选中第四个的时候提示超过了3个, 点解alert框取消后, 将最后一个选中的checkbox取消选中 <script> $(document).re ...

  7. Java for LeetCode 222 Count Complete Tree Nodes

    Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from W ...

  8. 15.SpringMVC和Spring上下文关系(为什么SpringMVC可以调用到Spring)

    springmvc上下文继承于spring, 也就是springmvc的上下文可访问spring上下文,在springmvc的上下文中可取得spring bean. spring上下文是spring启 ...

  9. diff & pattch 命令

    基础知识 该命令的功能为逐行比较两个文本文件,列出其不同之处.它比comm命令完成更复杂的检查.它对给出的文件进行系统的检查,并显示出两个文件中所有不同的行,不要求事先对文件进行排序. 语法:diff ...

  10. 一道常考fork题挖掘

    #include <stdio.h> #include <sys/types.h> #include <unistd.h> int main(void) { int ...