musher0 wrote:Code: Select all
free -m | awk '$1 ~ /Mem/ { print $2,$4 }'
Today I was in the need to get specific results from -->
uptime <-- to show some statistics in a gui. The output of -->
uptime <-- varies dependent on how long the computer is running.
So I wrote a small line to get the desired information.
Code: Select all
UPTIME="`uptime | cut -d ' ' -f 4 | cut -d ',' -f 1` hours"
But after the computer was running for more than 24 hours this line returned just -->
1 <-- instead of e.g.
25:43.
So I was in the need to modify the above line of code.
Thanks to the coded line above by musher0 it seems I'm going to understand -->
awk <-- at least a little. So, here's how I extracted that desired information when the computer is running for more than 24 hours.
Code: Select all
# Get up-time of running System
UPTIME="`uptime`"; echo "$UPTIME" > /tmp/upt;
if (grep 'day' /tmp/upt >/dev/null) then
UPTIME1=`uptime | awk '$2 ~ /up/ { print $3,$4,$5 }' | cut -d ',' -f 1`
UPTIME2=`uptime | awk '$2 ~ /up/ { print $3,$4,$5 }' | cut -d ',' -f 2`
UPTIME="$UPTIME1, $UPTIME2 hours"
else
UPTIME="`uptime | cut -d ' ' -f 4 | cut -d ',' -f 1` hours"
fi
Of course, I'm sure there's some smarter solution by the experts here. Though, I'm somehow glad to have understood a bit more of those special functions.
Thank you, musher0 !