For example, another way which may prove to be a better alternative for obtaining the uptime would be to source if directly from /proc/uptime (assuming that this interface is available to you)
I understand the sentiment here and often this approach makes sense but I don't think it does in this case.
The output from Solaris's stock uptime is close enough to GNU's that the regex would work without modification. So would IRIX's. And OpenBSD's. None of those systems has a /proc/uptime though. Using the tool in this case is far more portable.
As the uptime program is a stable enough tool that its interface is unlikely to change, using it probably should not be regarded as a maintenance risk either.
Getting your data from another program isn't inherently a bad thing. Nor should it to be shunned in lieu of any alternative. The key is to retrieve your data from an interface that is as stable and portable as possible. In this case, the data source he wanted to use is more standard than the one you suggested.
-sauoq "My two cents aren't worth a dime.";
In reply to Re: Re: Parsing 'uptime' output
by sauoq
in thread Parsing 'uptime' output
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |