So I've been experimenting with Bash not too long ago, and I want to manipulate the output from the "uptime" command. I managed to change the output of up x minutes to 0:05 for example if the up time is 5 minutes, but the rest of the things disappear.
What method should I use to also display the time, the amount of users and its load average without affecting my current up time output.
This is the desired output: 21:08:13 up 0:10, 3 users, load average: 0.30, 0.30, 0.25
Any help would be appreciated!
since="`uptime --since`"
start="`date --date "$since" '+%s'`"
now="`date '+%s'`"
sec=$((now-start))
days=$((sec/(60*60*24)))
sec=$((sec-days*(60*60*24)))
hr=$((sec/(60*60)))
sec=$((sec-hr*(60*60)))
min=$((sec/60))
sec=$((sec-min*60))
rest="$(uptime | perl -npe'{s/(.*,\s+)(\d+\s+user)/$2/}')"
printf "%d(days), %02d:%02d:%02d(hms), %s\n" $days $hr $min $sec "$rest"
CURRENT OUTPUT
0(days), 00:34:00(hms), 3 users, load average: 0.09, 0.14, 0.14