Quote:
Originally Posted by kkrrss
I want to take the output of ( $UPTIME - $MEMFILE) in minutes and seconds.
|
It's a little easier to work with command substitution is you use
$( ... ) instead of backticks. You can do arithmetic in the shell using $(( ... )) and can use addition, subtraction, multiplication, division, exponents, and modulus.
Here is a variant of your script set to do the first part of the calculation to get seconds, in preparation for then calculating the minutes.
Code:
#!/bin/sh
memfile=lock-file
date +%s > $memfile
sleep 130
then=$(head -n 1 $memfile)
now=$(date +%s)
downtime=$(( $now - $then ))
seconds=$(( $downtime % 60 ));
echo Downtime was X minutes and $seconds seconds
Can you see how to modify it to get minutes?