BEGINJOB="PN4949D" # Can set to $1 to accept as 1st arg
ENDJOB="FO1008D" # Can set to $2 to accept as 2nd arg
regexFirst="$myDate.*BEGIN JOB /srv/uni/PROD/PNRUN/$BEGINJOB"
regexLast="$myDate.*END JOB /srv/uni/PROD/PNRUN/$ENDJOB"
# Find First time
FIRST=$(sed -n "/$regexFirst/p" $logPathLogDay.$myDate | head -1)
FIRST=$(echo $FIRST | sed -n 's/.*\([0-2][0-9]:[0-5][0-9]:[0-5][0-9]\).*/\1/p')
echo "First job started at $FIRST"
# Find Last time
LAST=$(sed -n "/$regexLast/p" $logPathLogDay.$myDate | tail -1)
LAST=$(echo $LAST | sed -n 's/.*\([0-2][0-9]:[0-5][0-9]:[0-5][0-9]\).*/\1/p')
echo "Last job ended at $LAST"
# feeding variables by using read and splitting with IFS
IFS=: read first_hour first_min first_sec <<< "$FIRST"
IFS=: read last_hour last_min last_sec <<< "$LAST"
# the 10# is there to avoid errors with leading zeros
# by telling bash that we use base 10
total_hours=$((10#$last_hour - 10#$first_hour))
total_minutes=$((10#$last_min - 10#$first_min))
total_secs=$((10#$last_sec - 10#$first_sec))
echo "Tonight's work took $total_hours hours $total_minutes minutes and $total_secs seconds"
This script will look at the current date, and will search for that dates file, and the first occurrence of BEGIN and the last occurrence of END and then compare the time stamps.
First job started at 19:00:01
Last job ended at 24:00:01
Tonight's work took 5 hours 0 minutes and 0 seconds
This is a quick script I threw together, you can clean it and modify output, throw it into a function if needed etc.
*EDIT: Also, to run this script just add to your crontab to run daily at a time you prefer.
**EDIT: I added the variables for the begin and end regex.
I turned what looks to be the Job Reference # as variables, so you can easily change it or even have it passed as an argument.
Lastly, I put the path to the log as a variable so that can be changed easily as well.
As a side note, I added the comments in the script, albeit not the most detailed, but they are there so you can follow the script and make changes to suit your needs. As with any script, the customization can be endless!
You can also modify the date to be like:
myDate=$(date --date="1 day ago" +'%d-%m-%Y') if you prefer to have this look through previous day logs.