<div dir="ltr">Thanks for all your tips!<br><br>I found that the information is basically available in 'last -x'.<br><br>Below is a rough script I put together to estimate total times rounded to hours:<br><br>Thanks,<br>
-tom<br><br>--------------------------------<br><br>#!/bin/bash<br><br><br>#<br># Compute total hours machine has been running, minus time it was turned off.<br># Based on output from 'last -x'<br>#<br><br><br>STOP_F=/tmp/stop<br>
START_F=/tmp/start<br><br>last -x |awk '/shutdown/ {print $5, $6, $7, $8}' |tac > $STOP_F<br>last -x |awk '/reboot/ {print $5, $6, $7, $8}' |tac > $START_F<br># Start times (should be 1 more than shutdown times):<br>
<br># get rid of 1st start line since machine is still up<br>sed -i '1d' $START_F<br><br>#<br># Read 1 line from each file and compare<br># (see redirection at end of while loop<br>#<br>while read STOP <&8<br>
do<br> read START <&7<br><br> # compute time machine was stopped<br> start_s=$(date -d "$START" +%s)<br> stop_s=$(date -d "$STOP" +%s)<br><br> ((duration = start_s - stop_s))<br>
((tot_hours = duration / (60*60) ))<br><br> echo total hours stopped = $tot_hours<br> ((saved_hours+=tot_hours))<br><br>done 7<$START_F 8<$STOP_F<br><br>#<br># Compute total uptime since first boot<br>
#<br><br># seconds at 1st boot<br>first_s=$( date -d "$(last |tail -1 | awk '{$1=""; $2="" ;print }')" +%s)<br>now_s=$(date +%s)<br><br>((elapsed_hours= (now_s - first_s) /(60*60) ))<br>
echo Total elapsed hours = $elapsed_hours<br>echo Saved hours = $saved_hours<br>echo Total charged hours = $((elapsed_hours - saved_hours))<br></div>