Bash Scripting Basics (Variable Assignment, If, Loop)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
##################################################
# Benchmark the processing time when wkhtmltopdf
# converts an html file to a pdf file
##################################################

if [[ $1 = "" || $2 = "" || $3 = "" ]]; then
        echo "Usage: `basename $0` sourceFile.html destinationFile.pdf iteartionRunTime"
else
        _min=9999
        _max=0
        _total=0
        _iteration=$3
        for (( _i=1; _i<=$_iteration; _i++ ))
        do
                _start_time=`date +%s`
                echo "running $_i"
                ~MYUSER/bin/benchmarkWkhtmltopdf.sh $1 $2  > /dev/null 2>&1
                _end_time=`date +%s`
                _processing_time=$((_end_time-_start_time))
                if [ "$_processing_time" -lt "$_min" ]; then
                        _min=$_processing_time
                fi
                if [ "$_processing_time" -gt "$_max" ]; then
                        _max=$_processing_time
                fi
                _total=$(($_total+$_processing_time))
        done
       _processing_time_average=$(echo - | awk "{print $_total/$_iteration}")
        echo "Processing time avg: $_processing_time_average  min:$_min  max:$_max total:$_total"
fi
This entry was posted in Bash, Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


− 3 = two