Written by SenthilKumar Rasan while we were working at another customer site.
Modified it a bit to work with ksh.