簡體   English   中英

如何在 CGI shell 腳本中執行命令

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

我想在 CGI shell 腳本中執行命令,例如

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

並在 CGI 中獲取命令的輸出並在 CGI shell 腳本中顯示它。

開始echo Content-type: text/plain; echo echo Content-type: text/plain; echo 例子:

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

編輯:在添加的下方,OP 需要一個文本文件。

接下來考慮你想要什么, httpd 守護進程提供的文本文件? 當上面的腳本被調用時,調用

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

您也可以制作一個 html 文件,不需要 content-type:

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

但現在它不是有效的 HTML。 您不想轉義所有代碼,只需將您的內容添加到預先格式化的塊中

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

每次查看靜態文件時都不會更改,因此可以使用 crontab 使其更加動態。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM