print_help() { echo"-o set the output file name. (default: out.png)" echo"-t set the graph type. (one of ‘filledcurve’, ‘lines’. default: ‘filledcurve’)" echo"set graph color. (in hexadecimal form, default: #1E90FF)" echo"set the number of point should use. (must be set. should be in range[60-600]" echo"Read LOGFILE environment variable. If it is not set, use /tmp/sysmonitor" }
# Parse the arguments whilegetopts"ho:t:c:n:" opt do case"$opt"in h) print_help; exit 1 ;; o) outName=$OPTARG ;; t) graphType=$OPTARG ;; c) graphColor=$OPTARG ;; n) pointNumber=$OPTARG ;; *) exit 1 ;; esac
done
# check graph type, which must be filledcurve or lines. if [ "$graphType" ] ; then if [ "$graphType" != "filledcurve" ] && [ "$graphType" != "lines" ] ; then echo"type should be one of 'filledcurve' and 'lines'." fi if [ "$graphType" == "filledcurve" ] ; then graphType="filledcurve y1=0" fi fi
# check graph color, wich must fit #[0-9a-f]{6} if [ "$graphColor" ] ; then tmp=`echo$graphColor | grep '^#[0-9a-f]\{6\}' ` if [ -z "$tmp" ] ; then echo"color format error." exit fi fi
# check point number range in 60 ~ 600 if [ -z $pointNumber ] || [ "$pointNumber" -lt 60 ] || [ "$pointNumber" -gt 600 ] ; then print_usage exit fi
# check input files's location
inputFile=`printenv LOGFILE`
#generate a reverse data tempInput="input2" `tail -r -n $pointNumber${inputFile:="/tmp/sysmonitor"} | awk '{ print -NR" "$1}' > $tempInput`
#generate a temp plt file tempFile="temp.plt" `touch $tempFile`