我需要在bash中创建一个CGI,以便可以从gnuplot脚本生成图形。
目前,我使用两页:在第一页中,我们可以找到一个“生成按钮”:
#!/bin/bash
echo "Content-type: text/html"
echo ""
cat << EOT
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Cluster Graph </title>
</head>
<body>
<p>Please press the button to generate the graph ! </p>
<form action="submit.sh" target="_blank">
<button name="button"> Generate !</button>
</form>
</body>
</html>
EOT
如果单击它,第二页上会出现一个新标签:
#!/bin/bash
echo "Content-type: text/html"
echo ""
cat <<EOT
<html>
<head>
<title> Cluster Graph </title>
</head>
<body>
`cat gnuplot_test.txt | gnuplot`
</body>
</html>
EOT
那应该执行我的gnuplot脚本:
f(w) = (strlen(w) > 10 ? word(w, 1) . "\n" . word(w, 2) : w)
set title "CLUSTER 1"
set terminal png truecolor size 960, 720
set output "cluster1.png"
set bmargin at screen 0.1
set key top center
set grid
set style data histograms
set style fill solid 1.00 border -1
set boxwidth 0.7 relative
set yrange [0:]
set format y "%g%%"
set datafile separator ","
plot 'CLUSTER_ALE01.txt' using 2:xtic(f(stringcolumn(1))) title " CPU consumption (%) ", \
'' using 3 title " RAM consumption (%)", \
'' using 0:($2+1):(sprintf("%g%%",$2)) with labels notitle, \
'' using 0:($3+1):(sprintf(" %g%%",$3)) with labels notitle
最后,我希望图形出现在页面上,但是目前,我希望看到它在我的目录/ cgi-bin /中生成。
问题是:我的图形没有生成,我也不知道为什么。你能告诉我我的errors_log吗? :
[Tue Apr 09 11:36:28.502341 2019] [cgi:error] [pid 18412] [client ::1:39750] AH01215: , referer: http://localhost/cgi-bin/index.sh
[Tue Apr 09 11:36:28.502443 2019] [cgi:error] [pid 18412] [client ::1:39750] AH01215: line 0: warning: Skipping unreadable file "CLUSTER_ALE01.txt", referer: http://localhost/cgi-bin/index.sh
[Tue Apr 09 11:36:28.502653 2019] [cgi:error] [pid 18412] [client ::1:39750] AH01215: , referer: http://localhost/cgi-bin/index.sh
[Tue Apr 09 11:36:28.502669 2019] [cgi:error] [pid 18412] [client ::1:39750] AH01215: , referer: http://localhost/cgi-bin/index.sh
[Tue Apr 09 11:36:28.502762 2019] [cgi:error] [pid 18412] [client ::1:39750] AH01215: line 0: warning: Skipping unreadable file "CLUSTER_ALE01.txt", referer: http://localhost/cgi-bin/index.sh
[Tue Apr 09 11:36:28.502952 2019] [cgi:error] [pid 18412] [client ::1:39750] AH01215: , referer: http://localhost/cgi-bin/index.sh
[Tue Apr 09 11:36:28.502968 2019] [cgi:error] [pid 18412] [client ::1:39750] AH01215: , referer: http://localhost/cgi-bin/index.sh
[Tue Apr 09 11:36:28.503055 2019] [cgi:error] [pid 18412] [client ::1:39750] AH01215: line 0: warning: Skipping unreadable file "CLUSTER_ALE01.txt", referer: http://localhost/cgi-bin/index.sh
[Tue Apr 09 11:36:28.503117 2019] [cgi:error] [pid 18412] [client ::1:39750] AH01215: line 0: No data in plot, referer: http://localhost/cgi-bin/index.sh
[Tue Apr 09 11:36:28.503126 2019] [cgi:error] [pid 18412] [client ::1:39750] AH01215: , referer: http://localhost/cgi-bin/index.sh
谢谢!