Today I worked a little on the new NUKI versions. Finally, I brought order to her, and I want to fix it just before I release the last stable one, probably the final version. So I had the idea to check how many days is uptime on the receiver, that most of me have problems after being around for a long time, so I decided to do through 10 days a prophylactic restart. I quickly drew a conveyor to clear my days of other variables because the result of the uptime command is quite unpleasant to work with.
# uptime 12:13:57 up 30 days, 20:07, 1 user, load average: 0.00, 0.00, 0.00
So the order in question is filtered only by the super conveyor 😛
uptime | awk -F'up' '{ print $2 }' | awk -F'days' '{ print $1 }'
As if working hours are days the result is an integer with days, and if it is hours the result is similar to
[email protected]:~$ uptime | awk -F'up' '{ print $2 }' | awk -F'days' '{ print $1 }' 1:34, 5 users, load average: 0.46, 0.39, 0.41 [email protected]:~$
Because of which goes through a check for the type of value
if echo $days | grep "^[0-9]*$" > /tmp/null then echo "Uptime in days is $days" else echo "Uptime isnt in days" fi
Simply easily and clearly in the if the construction checks whether the value contains only digits with a regular expression grep “^[0-9]*$”.