Do not depend on /proc for calculating runtime
authorMichael Prokop <mika@grml.org>
Fri, 5 Jun 2020 15:44:41 +0000 (17:44 +0200)
committerMichael Prokop <mika@grml.org>
Fri, 5 Jun 2020 15:44:41 +0000 (17:44 +0200)
For example when running grml-live inside a docker
environment, /proc doesn't necessarily exist.
Instead use seconds since the epoch as base for calculating runtime.

Development time sponsored by Sipwise GmbH

grml-live

index ce6cb35..7dc20f8 100755 (executable)
--- a/grml-live
+++ b/grml-live
@@ -579,7 +579,8 @@ if [ -n "$CONFIG" ] ; then
    fi
 fi
 
-start_seconds=$(cut -d . -f 1 /proc/uptime)
+SECONDS=unknown
+start_seconds="$(date +%s)"
 log "------------------------------------------------------------------------------"
 log "Starting grml-live [${GRML_LIVE_VERSION}] run on $(date)"
 log "Using local config file: $LOCAL_CONFIG"
@@ -1692,7 +1693,10 @@ fi
 # }}}
 
 # finalize {{{
-[ -n "$start_seconds" ] && SECONDS="$[$(cut -d . -f 1 /proc/uptime)-$start_seconds]" || SECONDS="unknown"
+if [ -n "${start_seconds}" ] ; then
+  end_seconds="$(date +%s)"
+  SECONDS="$(( end_seconds - start_seconds ))"
+fi
 log "Successfully finished execution of $PN [$(date) - running ${SECONDS} seconds]"
 
 dpkg_to_db # make sure we catch the last log line as well, therefore execute between log + einfo