【发布时间】:2017-11-18 13:45:17
【问题描述】:
我有一小段代码,由于某种原因,从http://localhost/cgi-bin/sysinfo.sh 运行时无法执行。我在 CentOS 7 的虚拟机上。我会尽我所能获得帮助。我似乎无法正确理解这些缩进,但它们在 Vi 中是正确的。
#!/bin/bash
echo -e "Content-type: text/html\r\n\n"
echo "
<html>
<head>
<title>Bash as CGI</title>
</head>
<body>
<h3>General system information for host $(hostname -s). </h3>
<h4>Memory Info</h4>
<pre> $(free -m) </pre>
<h4>Disk Info:</h4>
<pre> $(df -h) </pre>
<h4>Logged in user</h4>
<pre> $(w) </pre>
<hr>
Information generated on $(date)
</body>
</html>
当我将它作为 shell 脚本运行时……html 标记都会与命令的输出一起显示出来。
内容类型:文本/html
<html>
<head>
<title>Bash as CGI</title>
</head>
<body>
<h3>General system information for host localhost</h3>
<h4>Memory Info</h4>
<pre> total used free shared
buff/cache available
Mem: 1775 994 137 20 643
540
Swap: 2047 0 2047 </pre>
<h4>Disk Info:</h4>
<pre> Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 47G 9.7G 38G 21% /
devtmpfs 873M 0 873M 0% /dev
tmpfs 888M 4.2M 884M 1% /dev/shm
tmpfs 888M 9.1M 879M 2% /run
tmpfs 888M 0 888M 0% /sys/fs/cgroup
/dev/sda1 1014M 235M 780M 24% /boot
tmpfs 178M 4.0K 178M 1% /run/user/42
tmpfs 178M 44K 178M 1% /run/user/0 </pre>
<h4>Logged in user</h4>
<pre> 21:33:21 up 2:01, 3 users, load average: 0.06, 0.04, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 :0 20:45 1.00s 0.14s 0.00s w
root :0 :0 20:45 ?xdm? 1:11 0.11s
/usr/libexec/gnome-session-binary --session gnome-classic </pre>
<hr>
Information generated on Sat Nov 18 21:33:21 EST 2017
</body>
</html>
【问题讨论】:
-
你的网络服务是什么,你是如何配置它来执行
.sh脚本的? -
您的文件是否包含右双引号(您粘贴的内容没有)?
-
“无法执行”不是对您的问题的非常有用的描述。您究竟看到了什么意外行为?将什么写入 Web 服务器错误日志?
-
这和 Perl 有什么关系?
-
@simbabque: 所有 CGI 与 Perl 有关系。我很惊讶你不知道:-)