0

How would I calculate how long my process took in hours in the Bash script below?

So far I have it showing minutes and seconds, but my process is taking so long that I need to account for the amount of hours its taking.

#!/bin/bash

start=$(date + "%s")
end=$(date + "%s")
runtime=$((end - start))
echo "Process took $((runtime/60)) minutes and $((runtime % 60)) seconds."
methuselah
  • 12,766
  • 47
  • 165
  • 315
  • 1
    `ps -oetime= $$ | xargs` is a bit of a hack, but it’s portable, and even includes the number of days. – Biffen Jan 29 '21 at 10:28
  • By the way, you don't need `$start` and $`end`. Bash has the built-in variable `$SECONDS` which always contains the seconds since the start of the script. Alternatively, there is the built-in command `times` which already formats the time as `1m2.345s` – Socowi Jan 29 '21 at 10:34

0 Answers0