![](/img/trans.png)
[英]How to send a variable form my bash cgi script to my index html page?
[英]CGI : How to put Gnuplot command in my bash script?
我正在设置一个bash / html CGI,它允许我使用GnuPlot生成图形。
为此,我在bash / html中有两个CGI页面:
第一页包含一个简单的“生成”按钮,用于打开新页面并执行我的gnuplot脚本,以及一个先前已填充不同集群名称的列表框。
通过“生成”按钮打开的第二页显示我的图表。
我的问题是:如何将gnuplot命令放入bash / html的CGI页面?
这是我的第一页的代码,允许我选择我感兴趣的集群:
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo '
<html>
<head>
<meta http-equiv="Content-Type" content="test/html"; charset=UTF-8">
<title> CLUSTER GRAPH </title>
<h1> Cluster Graph <font size=3> <a href="Index.sh">[ Index ]</a> </font> </h1>
<hr size="4" color="blue">
</head>
<body>
<p> Choose a Cluster and press the button to generate the graph ! </p>'
Cluster_Name=$(cat ClusterFullList.csv | awk '{print $3}' | sort |uniq)
echo "<form action="Script_test.sh" method="post">"
echo "<select name="CLUSTER">"
echo "$Cluster_Name" | while read CLUSTER; do
echo " <option value="$CLUSTER">$CLUSTER</option>"
done
echo "</select>"
echo"<br><br>"
echo "<input type="submit" value="Generate">"
echo "</form>"
echo '
</body>
</html>
'
这是我的第二页的代码,我的图表应该出现在该代码中:
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo "
<html>
<head>
<title> CLUSTER GRAPH </title>
<h1> Cluster Graph <font size=3> <a href="Index.sh">[ Index ]</a></font></h1>
<hr size="4" color="blue">
</head>
<body>
<img src="$test.png">
<PRE>"
read a
test=`echo $a | cut -d'=' -f2`
echo "$test"
echo " f(w) = (strlen(w) > 10 ? word(w, 1) . "\n" . word(w, 2) : w) " >> gnuplot_script_test.txt
echo " set title $test " >> gnuplot_script_test.txt
echo " set terminal png truecolor size 960, 720 " >> gnuplot_script_test.txt
echo ' set output "$test.png" ' >> gnuplot_script_test.txt
echo " set bmargin at screen 0.1 " >> gnuplot_script_test.txt
echo " set key top center " >> gnuplot_script_test.txt
echo " set grid " >> gnuplot_script_test.txt
echo " set style data histograms " >> gnuplot_script_test.txt
echo " set style fill solid 1.00 border -1 " >> gnuplot_script_test.txt
echo " set boxwidth 0.7 relative " >> gnuplot_script_test.txt
echo " set yrange [0:] " >> gnuplot_script_test.txt
echo " set format y "%g%%" " >> gnuplot_script_test.txt
echo " set datafile separator "," " >> gnuplot_script_test.txt
echo ' plot "/var/www/cgi-bin/CLUSTER_1.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 ' >> gnuplot_script_test.txt
gnuplot gnuplot_script_test.txt
rm gnuoplot_script_test.txt
echo "
</PRE>
</body>
</html>
"
这个想法是:
命令:
read a
test=`echo $a | cut -d'=' -f2`
echo "$test"
允许我检索我的查询字符串,这是我感兴趣的集群的名称(集群名称在我的第一页的列表框中)
我执行gnuplots命令并每次在文件“gnuplot_script_test.txt”中发送它们,然后我通过命令执行它:
gnuplot gnuplot_script_test.txt
然后txt文件通过以下命令删除自身:
rm gnuplot_script_test.txt
我想确保通过我的查询字符串检索的集群名称,我可以将它放在我的gnuplot命令中。 为此,我将变量“$ test”(包含我的集群的名称)放在行中:
echo" set title "$test""
将我的群集名称放在我的标题中
echo ' set output "$test.png" '
给我的png我的集群的名称
但是,当我在第一页上选择我的群集时,我单击生成,我的群集名称在我的第二页上显示良好,但图像未生成...
你能告诉我为什么吗 ?
谢谢 !
您在设置之前使用$test
变量。
你可以找到有用的heredoc http://tldp.org/LDP/abs/html/here-docs.html然后你可以做到:
gnuplot <<EOF_GNUPLOT
# your gnuplot code here - e.g.:
reset
set term png truecolor enhanced size 1050,1050
set xtics out
# ...
EOF_GNUPLOT
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.