简体   繁体   English

如何在 CGI shell 脚本中执行命令

[英]How to execute commands in a CGI shell script

I want to execute commands in a CGI shell script like我想在 CGI shell 脚本中执行命令,例如

 ls -la
 ln
 pwd
 uname
 chmod
 chown
 cat
 and others ... etc ...

and get the output of commands in CGI and show it in CGI shell script.并在 CGI 中获取命令的输出并在 CGI shell 脚本中显示它。

Start with echo Content-type: text/plain; echo开始echo Content-type: text/plain; echo echo Content-type: text/plain; echo . echo Content-type: text/plain; echo Example:例子:

#!/bin/bash
echo Content-type: text/plain
echo
echo First normal line
pwd
uname
chmod

Edit: beneath added, OPs wants a textfile.编辑:在添加的下方,OP 需要一个文本文件。

Next consider what you want, A text file served by the httpd daemon?接下来考虑你想要什么, httpd 守护进程提供的文本文件? When above script is called example, call当上面的脚本被调用时,调用

htdocs=/home/saba/http/htdocs
mkdir -p ${htdocs}
example.sh > ${htdocs}/static_output.txt

You can also make a html file, the content-type is not needed:您也可以制作一个 html 文件,不需要 content-type:

htdocs=/home/saba/http/htdocs
mkdir -p ${htdocs}
example.sh | grep -v "Content-type" > ${htdocs}/static_output.html

But now it is not valid HTML.但现在它不是有效的 HTML。 You do not want to go escaping all code, just add your content in a preformatted block您不想转义所有代码,只需将您的内容添加到预先格式化的块中

htdocs=/home/saba/http/htdocs
mkdir -p ${htdocs}
echo "<html><body><pre>" > ${htdocs}/static_output.html
example.sh | grep -v "Content-type" >> ${htdocs}/static_output.html
echo "</pre></body></html>" >> ${htdocs}/static_output.html

Static files don't change each time you look at it, making it more dynamicly could be done with crontab.每次查看静态文件时都不会更改,因此可以使用 crontab 使其更加动态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM