Hi!
I want to extract the uptime from the output of the uptime command.
The output:
11:53 up 3:02, 2 users, load averages: 0,32 0,34 0,43
I just need the "3:02" part. How can I do this?
Dirk
Hi!
I want to extract the uptime from the output of the uptime command.
The output:
11:53 up 3:02, 2 users, load averages: 0,32 0,34 0,43
I just need the "3:02" part. How can I do this?
Dirk
echo $(uptime) | sed 's/^.\+up\ \+\([^,]*\).*/\1/g'
uptime | awk '{print $3}'
I think this works only if uptime < 1 day
Right, thanks, it should be something like:
uptime | awk -F, '{sub(".*up ",x,$1);print $1}'
Here's a couple more "uptime" examples to play with.
They are UK number format (unlike the O/P who has a comma as a decimal separator).
Note that the format increases the number of comma-separated fields and also changes if the uptime is an exact number of hours.
12:55pm up 105 days, 21 hrs, 2 users, load average: 0.26, 0.26, 0.26
1:41pm up 105 days, 21:46, 2 users, load average: 0.28, 0.28, 0.27
It can be done by converting commas to newlines and ignoring everything from the line containing "users". My trial script got too convoluted to post!
>> uptime | awk -F, '{sub(".*up ",x,$1);print $1}'
Exp-
# uptime
11:29:16 up 47 days, 20:34, 2 users, load average: 0.01, 0.01, 0.00
# uptime | awk -F, '{sub(".*up ",x,$1);print $1}'
47 days
It lists only days but there is no output for hours 20:34. So there is little modification:
# uptime | awk -F, '{sub(".*up ",x,$1);print $1,$2}'
47 days 20:34