enhanced command line parsing.

This commit is contained in:
2026-02-01 10:21:35 +01:00
parent 34d8ba7214
commit 08acce525b
3 changed files with 65 additions and 21 deletions

View File

@@ -10,34 +10,77 @@ usage() {
EOF
}
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
usage
exit 0
verbose=false
COLOR='red'
VALID_ARGS=$(getopt -o vho:c:t:l: --long verbose,help,output,color:,title:,logfile: -- "$@")
if [[ $? -ne 0 ]]; then
exit 1;
fi
# Eingabeparameter
LOGFILE="${1}"
OUTFILE="${2}"
TITLE="${3}"
echo "VALID_ARGS=${VALID_ARGS}"
eval set -- "$VALID_ARGS"
while [ : ]; do
# echo "aktueller Parameter: ${1}"
case "$1" in
-h | --help)
usage
exit 0
shift
;;
-l | --logfile)
LOGFILE="${2}"
echo "LOGFILE=${LOGFILE}"
shift 2
;;
-o | --output)
echo "1: ${1}, 2:${2},3:${3}"
OUTFILE="${2}"
echo "OUTFILE=${OUTFILE}"
shift 2
;;
-c | --color)
COLOR="${2}"
echo "COLOR=${COLOR}"
shift 2
;;
-t | --title)
TITLE="${2}"
echo "TITLE=${TITLE}"
shift 2
;;
-v | --verbose)
verbose=true
shift
;;
--) shift;
break
;;
esac
done
echo "Parameter geparsed."
# Eingabeparameter
if [ -z "$LOGFILE" ] || [ -z "$OUTFILE" ] || [ -z "$TITLE" ]; then
usage
exit 1
fi
gnuplot <<EOF
set terminal pngcairo size 1600,900
set output "$OUTFILE"
echo "generating plot from ${LOGFILE}"
gnuplot -e "
set terminal pngcairo size 1800,800;
set title "$TITLE"
set xlabel "Zeit (s)"
set ylabel "Temperatur (°C)"
set grid
set key top left
set output '${OUTFILE}';
set multiplot layout 1,2 title '${TITLE}';
set xlabel 'Zeit (s)';
set ylabel 'Temperatur (°C)';
set grid;
set key top left;
set title '${TITLE}';
plot '$LOGFILE' using 1:2 with lines lc rgb '${COLOR}' lw 2 title 'CPU-Temperatur'
"
# Linie rot, Dicke 2
plot "$LOGFILE" using 1:2 with lines lc rgb "red" lw 2 title "CPU-Temperatur"
EOF
echo "Plot erzeugt: $OUTFILE"
exit 0