Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过cgi执行bash脚本_Bash_Cgi - Fatal编程技术网

如何通过cgi执行bash脚本

如何通过cgi执行bash脚本,bash,cgi,Bash,Cgi,我正在尝试使用cgi从网页中调用bash脚本。我有它的部分工作,因为echo命令似乎工作,但其他命令不工作 我使用的是lighttpd,我有一个文件cgi.sh,叫做demo\u start.sh #!/bin/bash printf "Content-Type: text/plain\n\n" ip route get 1 | awk '{print $NF;exit}'>/srv/http/ip.txt file="/srv/http/ip.txt" ip_address=$(cat

我正在尝试使用cgi从网页中调用bash脚本。我有它的部分工作,因为echo命令似乎工作,但其他命令不工作

我使用的是lighttpd,我有一个文件cgi.sh,叫做demo\u start.sh

#!/bin/bash
printf "Content-Type: text/plain\n\n"

ip route get 1 | awk '{print $NF;exit}'>/srv/http/ip.txt
file="/srv/http/ip.txt"
ip_address=$(cat ${file})

echo ${ip_address}

file="/srv/http/demo_count.txt"
count=$(cat ${file})

((count++))
echo ${count} > ${file}

echo Demo started ${count} times

sed -i".bak" '$d' /srv/http/index.html
sed -i '$ a <a href="http://'${ip_address}':'${count}'">Start Demo</a<br/>' /srv/http/index.html
cat/srv/http/cgi.sh

#!/bin/bash
. includes/srv/http/demo_start.sh
/usr/bin/bash /srv/http/demo_start.sh
cat/srv/http/demo_start.sh

#!/bin/bash
printf "Content-Type: text/plain\n\n"

ip route get 1 | awk '{print $NF;exit}'>/srv/http/ip.txt
file="/srv/http/ip.txt"
ip_address=$(cat ${file})

echo ${ip_address}

file="/srv/http/demo_count.txt"
count=$(cat ${file})

((count++))
echo ${count} > ${file}

echo Demo started ${count} times

sed -i".bak" '$d' /srv/http/index.html
sed -i '$ a <a href="http://'${ip_address}':'${count}'">Start Demo</a<br/>' /srv/http/index.html
#/bin/bash
printf“内容类型:文本/普通\n\n”
ip路由获取1 | awk'{print$NF;exit}'>/srv/http/ip.txt
file=“/srv/http/ip.txt”
ip_地址=$(cat${file})
echo${ip_地址}
file=“/srv/http/demo\u count.txt”
计数=$(cat${file})
((count++)
echo${count}>${file}
echo演示已启动${count}次
sed-i“.bak”'$d'/srv/http/index.html
sed-我得到$a

172.27.103.31

演示开始了8056次

如果我刷新,我会

172.27.103.31

演示开始了8057次

所有的echo命令都在工作,它可以正确地读写我的计数器文件。但是,sed命令不会运行,因为my index.html未更新

如果我在bash提示符下输入sh demo_start.sh,它将正常工作。当我通过cgi调用脚本时,如何运行所有命令


提前感谢

在printf头之后的shell脚本开头添加一个
set-x
exec 2>&1
,以查看更多调试输出,或者查看日志文件。此外,您的锚中还有一个输入错误:
非常好的建议,谢谢,这表明sed在编写临时文件时有权限错误。在printf头之后的shell脚本开头添加
set-x
exec 2>&1
,以查看更多调试输出,或者查看日志文件。此外,您的锚中还有一个输入错误:
非常好的建议,谢谢,这表明sed在编写临时文件时出现了权限错误。