#!/bin/sh usage="utp -a|-l FILE" if [ $# -eq "0" ]; then echo $usage; exit 65 fi while getopts ":a:l:" option; do case $option in a) p_start=$(head -n1 $OPTARG | cut -d' ' -f2) p_end=$(tail -n1 $OPTARG | cut -d' ' -f2) h_start=$(head -n1 $OPTARG | cut -d':' -f1) h_end=$(tail -n1 $OPTARG | cut -d':' -f1) h_diff=$(($h_end - $h_start)) m_start=$(head -n1 $OPTARG | cut -d':' -f2) m_end=$(tail -n1 $OPTARG | cut -d':' -f2) m_diff=$(($m_end - $m_start)) t_diff=$(($h_diff * 60 + $m_diff)) cut -d' ' -f2 $OPTARG | uniq -c > s sum_time=0 percent=100 echo -e "Percent:\tTime:" i=1 while [ $i -le $(wc -l s | cut -d' ' -f1) ]; do p=$(sed -n "${i}p" s | cut -c9-12 | sed "s/%//") if [ $p -lt $(($percent - 9)) ]; then sum_m=$(($sum_time / 60)) sum_s=$(($sum_time - $sum_m * 60)) echo -e "$percent - $(($percent - 9)):\t${sum_m}m${sum_s}s" percent=$(($percent - 10)) sum_time=0 fi s=$(sed -n "${i}p" s | cut -c5-7) sum_time=$(($sum_time + $s)) i=$(($i + 1)) done rm s sum_m=$(($sum_time / 60)) sum_s=$(($sum_time - $sum_m * 60)) echo -e "$percent - 01:\t${sum_m}m${sum_s}s" echo "The script was logging from $p_start to $p_end in $t_diff minutes.";; l) while true; do echo "$(date +%T), $(apm | cut -d' ' -f5)" | tee -a $OPTARG sleep 1 done;; *) echo $usage;; esac done