Created
May 24, 2024 21:53
-
-
Save dvinciguerra/1f7574501a1d9cf379907f10973bf4ea to your computer and use it in GitHub Desktop.
Ruby uptime cli stdout parsing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# getting uptime stdout | |
str = `uptime` | |
pp(str); | |
# parsing uptime | |
str.match( | |
/^(?<current>\d+:\d+)\s+(?<message>up (?<amount>\d+) (?<unit>days|minutes|seconds)),\s+(?<boot_at>\d+:\d+),\s+(?<users>(?<user_count>\d+) user|users),\s+(?<load_avgs>.*)\s$/ | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment