由于mysql查询,没有在shell脚本中输出

时间:2012-10-15 05:24:34

标签: mysql shell

这是我生成图表并将它们组合起来的脚本。 问题是当我给出输入并在终端中运行文件时,它在转储文件中显示为null。我认为它也没有执行mysql命令。如果我在命令本身给出输入datetime1,datetime2和moteid,Mysql命令工作正常。我无法找到我在mysql查询中出错的地方

datetime1=$1

DATETIME2 = $ 16 moteid = $ 3'/ P>

echo " \\documentclass[a4paper,12pt]{article} \

\\usepackage{graphicx} \

\\usepackage{subfigure} \

\\begin{document} \

\\begin{center} \

\\begin{Large} \

\\textbf{ A Network Management System} \\\ \

\\end{Large} \

\\end{center} \

\\vspace{5mm} \

{\bf Report }" > report.tex

flag=0
count_null=0


echo "\\begin{center} \

      {\bf Report generated } \

      \\end{center} " >> report.tex




mysql -u root -e "SELECT (b.l2framessent - a.l2framessent) AS netl2framessent,(b.Frames_Drop-a.Frames_Drop) AS netframesdrop,(b.ETX - a.ETX) AS netetx,CONVERT(endOfInterval*500, DATETIME) endOfInterval FROM (SELECT datetime DIV 500 startOfInterval,l2framessent,Frames_Drop,ETX FROM Statistics3,(SELECT MIN(datetime) mindate FROM Statistics3 WHERE ipaddress=\"$moteid\" AND datetime BETWEEN \"$datetime1\" AND \"$datetime2\" GROUP BY datetime DIV 500) b WHERE ipaddress=\"$moteid\" AND datetime = mindate) a, (SELECT datetime DIV 500 endOfInterval, l2framessent,Frames_Drop,ETX FROM Statistics3, (SELECT MIN(datetime) mindate FROM Statistics3 WHERE ipaddress = \"$moteid\" AND datetime BETWEEN \"$datetime1\" AND \"$datetime2\" GROUP BY datetime DIV 500) b WHERE ipaddress = \"$moteid\" AND datetime = mindate) b WHERE endOfInterval = startOfInterval+ 1 ;" >> dump

sed '1d' dump



##### ETX ######

echo "reset \

set terminal png \

set xdata time \

set timefmt \"%H:%M:%S\" \

set xlabel \"Time\" \

set ylabel \"netetx\" \

set title \"ETX\" \

set grid \

plot \"dump\" using 4:3 title \"ETX\" " >> etx.sh

gnuplot etx.sh > etx.png


#L2 Frames Sent

echo "reset \

set terminal png \

set xdata time \

set timefmt \"%H:%M:%S\" \

set xlabel \"Time\" \

set ylabel \"netL2Framessent\" \

set title \"L2 Frames Sent\" \

set grid \

plot \"dump\" using 4:1 title \"L2 Frames Sent\" " >> frames.sh

gnuplot frames.sh > frames.png


#Frames Drop

echo "reset \

set terminal png \

set xdata time \

set timefmt \"%H:%M:%S\" \

set xlabel \"Time\" \

set ylabel \"netframesdrop\" \

set title \"L2 Frames Drop\" \

set grid \

plot \"dump\" using 4:2 title \"L2 Frames Drop\" " >> framesdrop.sh

gnuplot framesdrop.sh > framesdrop.png


##   TEX  FILE  GENERATION ####


echo "\\begin{figure}[h] \

\\begin{center} \

\\subfigure[ETX]{\label{fig:edge-1a}\includegraphics[width=2.6in,height=2.5in]{etx.png}} \

\\hspace{1mm} \

\\subfigure[L2 Frames Sent]{\label{fig:edge-1b}\includegraphics[width=2.6in,height=2.5in]{frames.png}} \



\\end{center} \

\\label{fig:edge} \

\\end{figure} \

\\begin{figure}[h] \

\\begin{center} " >> report.tex



echo "\\subfigure[L2 Frames Drop]{\label{fig:edge-2a}\includegraphics[width=2.5in,height=2.5in]{framesdrop.png}} \

\\hspace{3mm}  >> report.tex



\\end{center} \

\\label{fig:edge} \

\\end{figure} \

\\clearpage " >> report.tex




echo "\\end{document} " >> report.tex

pdflatex report.tex > /dev/null

在终端运行我给出的输出, sh plot.sh“2012-09-25 15:45:00”“2012-09-29 18:45:00”“5” 输出是

plot "dump" using 4:3 title "ETX" 
                            ^
"etx.sh", line 12: warning: Skipping data file with no valid points

plot "dump" using 4:3 title "ETX" 
                                  ^
"etx.sh", line 12: x range is invalid


plot "dump" using 4:1 title "L2 Frames Sent" 
                            ^
"frames.sh", line 12: warning: Skipping data file with no valid points

plot "dump" using 4:1 title "L2 Frames Sent" 
                                             ^
"frames.sh", line 12: x range is invalid


plot "dump" using 4:2 title "L2 Frames Drop" 
                            ^
"drop.sh", line 12: warning: Skipping data file with no valid points

plot "dump" using 4:2 title "L2 Frames Drop" 
                                             ^
"drop.sh", line 12: x range is invalid



RUN SUCCESSFUL (total time: 154ms)

如果我给这个mysql查询而不是那个,它的工作正常

mysql -u root -e "SELECT (b.l2framessent - a.l2framessent) AS netl2framessent,(b.Frames_Drop-a.Frames_Drop) AS netframesdrop,(b.ETX - a.ETX) AS netetx,CONVERT(endOfInterval*500, DATETIME) endOfInterval FROM (SELECT datetime DIV 500 startOfInterval,l2framessent,Frames_Drop,ETX FROM Statistics3,(SELECT MIN(datetime) mindate FROM Statistics3 WHERE ipaddress='moteid5' AND datetime BETWEEN '2012-09-25 15:45:00' AND '2012-09-25 18:45:00' GROUP BY datetime DIV 500) b WHERE ipaddress='moteid5' AND datetime = mindate) a, (SELECT datetime DIV 500 endOfInterval, l2framessent,Frames_Drop,ETX FROM Statistics3, (SELECT MIN(datetime) mindate FROM Statistics3 WHERE ipaddress = 'moteid5' AND datetime BETWEEN '2012-09-25 15:45:00' AND '2012-09-25 18:45:00' GROUP BY datetime DIV 500) b WHERE ipaddress = 'moteid5'AND datetime = mindate) b WHERE endOfInterval = startOfInterval+ 1 ;" >> dump

2 个答案:

答案 0 :(得分:1)

命令:

sed '1d'

没有给出输入文件,所以它从标准输入读取。所以它等着你输入一些东西。我怀疑你的意思是将mysql的输出传递给它,所以它应该是:

mysql -u root -e "SELECT ..." | sed 1d >> filename

答案 1 :(得分:0)

而不是5在mote,我必须给moteid5.Its现在没有显示任何错误