T
tecker2010
Hallo, bin sehr unerfahren was Bash angeht, daher dann doch der Entschluss hier zu fragen. Wir sollen den Quelltext (vergleich.sh)vervollständigen um damit 2 .cpp Datein zu kompilieren di im gleichen Ordner liegen zu starten und die Ergebnisse dann mit gnuplot grafisch darstellen. Die .cpp`s (normal.cpp und process.cpp)sind im Grunde Schleifen bei denen ich angebe wie oft diese durchlaufen werden.
Aber irgendwie muss ich ja die PARAMETER noch eingeben in dem Bash Script. Habe schon einiges versucht wie z.B. for i in `find /opt/*.cpp`oder so sowas aber ich bekomme immer den Fehler:
'ergleich.sh: line 11:syntax error near unexpected token
'ergleich.sh: line 11: `do
Ausführen tue ich die Shell mit bash vergleich.sh
Jemand eine Idee??
Aber irgendwie muss ich ja die PARAMETER noch eingeben in dem Bash Script. Habe schon einiges versucht wie z.B. for i in `find /opt/*.cpp`oder so sowas aber ich bekomme immer den Fehler:
'ergleich.sh: line 11:syntax error near unexpected token
'ergleich.sh: line 11: `do
Ausführen tue ich die Shell mit bash vergleich.sh
Jemand eine Idee??
Code:
#!/bin/bash
if [ $# = 0 ]; then
echo "Usage: $0 file1.cpp file2.cpp ..."
exit 1
fi
for PARAMETER
do
if [[ $PARAMETER != *.cpp ]]; then
echo "Only \"*.cpp\" Files!"
exit 2
fi
if [ ! -f $PARAMETER ]; then
echo "Sorry, the \"$PARAMETER\" doesn't exist!"
exit 3
fi
done
for PARAMETER
do
echo "compile: $PARAMETER"
c++ -o ./${PARAMETER%.cpp} ./$PARAMETER -lpthread -Wno-deprecated
done
echo -n "parameter loop1 (<= 500): "
read RANGE1
echo -n "parameter loop2 (<= 5000): "
read LOOP2
COUNT=1
echo "wait ..."
# create here document for gnuplot
echo "#!/bin/bash" > plot.tmp
echo "gnuplot -persist <<ende" >> plot.tmp
echo "set title \" Processes vs. Threads\"" >> plot.tmp
echo "set xlabel \"loop1 [loop2=$LOOP2]\"" >> plot.tmp
echo "set ylabel \"Time in [s]\"" >> plot.tmp
echo "plot \"./$1.tmp\" using 1:2 smooth unique title \"$1\"" >> plot.tmp
for PARAMETER
do
for ((LOOP1=5; LOOP1<=$RANGE1; LOOP1=LOOP1+5))
do
for ((i=1; i<=$COUNT;i=i+1))
do
echo -n "$LOOP1 " >> ./$PARAMETER.tmp
/usr/bin/time -f %e -a -o $PARAMETER.tmp ./${PARAMETER%.cpp} $LOOP1 $LOOP2
done
done
if [ $PARAMETER != $1 ]; then
echo "replot \"./$PARAMETER.tmp\" using 1:2 smooth unique title \"$PARAMETER\"" >> plot.tmp
fi
rm -f ${PARAMETER%.cpp}
done
# .png or .ps picture
FILENAME=`date +%Y%m%d-%H%M%S`
echo "set output \"$FILENAME.png\"" >> plot.tmp
echo "set terminal png" >> plot.tmp
#echo "set terminal postscript color" >> plot.tmp
echo "set notitle" >> plot.tmp
#echo "replot \"./$PARAMETER.tmp\" using 1:2 smooth unique title \"$PARAMETER\"" >> plot.tmp
echo "replot" >> plot.tmp
echo "ende" >> plot.tmp
chmod +x ./plot.tmp
./plot.tmp
rm -f plot.tmp
for PARAMETER
do
rm -f $PARAMETER.tmp
done