Tuesday, 4 February 2014

Arithmetic inside Linux ksh script

Sometimes, you write a shell script and the need arises for a little arithemtic inside. There are a few ways to do this, below is the simplest way, in my opinion; this is a very simple example, to calculate the percentage done by a specific job:

#!/bin/ksh

total=27800
done=`grep 9k4dgqum1pkdh MYDB_ora_7519.trc |wc -l`


s=`echo "${done}*100/${total}" | bc`

echo "Completed : ${s}%"



No comments:

Post a Comment