从HTML执行Shell脚本 [英] Execute a shell script from HTML
本文介绍了从HTML执行Shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了一个简单的HTML代码,提交后它执行bash脚本. 该脚本位于正确的文件夹(cgi-bin)中. 当我在Firefox上加载此页面时.给出错误为
I have written a simple HTML code that upon submit, it executes a bash script. The script is in the correct folder, (cgi-bin). When I load this page on firefox. It gives an error as
/somePATH/cgi-bin/script.sh could not be opened because an unknown error occurred.
有关脚本权限的问题吗?我已经尝试过:
Is the problem about script permissions? I have tried:
chmod 777
这是HTML代码的一部分.
Here is a a part of the HTML code.
<form action="cgi-bin/script.sh" method="post">
<input type="submit" value="Call my Shell Script">
</form>
该脚本基本上只打印日期:
The script basically just prints the date:
#!/bin/bash
# get today's date
OUTPUT=$(date)
# script
echo "Content-type: text/html"
echo ""
echo "<html><head><title>Demo</title></head><body>"
echo "Today is $OUTPUT <br>"
echo "You can do anything with this Schell Script"
echo "</body></html>"
推荐答案
您可以使用服务器端语言.使用PHP相当简单
You can use a server side language. This is fairly easy with PHP
<?php
if(isset($_POST['submit']))
{
$output=shell_exec('sh /somePATH/cgi-bin/script.sh');
echo $output;
}
?>
<form action="" method="post">
<input type="submit" name="submit" value="Call my Shell Script">
</form>
包括所有其他HTML并使用扩展名.php
Include all your other HTML and save the file with an extension .php
这篇关于从HTML执行Shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文