Date: Thu, 20 Dec 2001 02:07:53 -0500 From: Jim Conner <jconner@enterit.com> To: freebsd-questions@FreeBSD.ORG Cc: "Steven Hetland" <shetland@reality-bytez.com>, <beginners@perl.org>, "KeN ClarK" <ken@quantifier.org> Subject: RE: extract uptime for linux box w/perl Message-ID: <5.1.0.14.0.20011220020635.0465b948@mail.enterit.com> In-Reply-To: <5.1.0.14.0.20011220014711.02b7fce8@mail.enterit.com> References: <LAEDKOOGKFANFCGIMPCMIENMCKAA.shetland@reality-bytez.com> <Pine.LNX.4.33.0112192256020.5354-100000@quantifier>
next in thread | previous in thread | raw e-mail | index | archive | help
At 02:01 12.20.2001 -0500, Jim Conner wrote: >-----BEGIN PGP SIGNED MESSAGE----- >Hash: SHA1 > >At 00:26 12.20.2001 -0500, Steven Hetland wrote: > > > -----Original Message----- > > > > > > right now i do > > > > > > w | head -1 > > > > > > and get what's below my signature. I want to clean that up, cutting it > > > after the # of users, so that everything after AND including the third > > > comma is removed from that line. Then take that and add it to my > > > signature > > > script. > > > >Maybe I misunderstood. I thought Ken was asking the opposite of what Jim > >posted... > > > >Indeed. He did ask to have the comma removed but I thought he wanted >everything after the third comma (shrug...hehehe). I just misread his >question. The second solution you posted would be what I would have >suggested to be the best. > > >If you want a least effort solution, you can do it without perl. Just > >modify your bash script: > > > > w | head -1 | cut -d, -f1-3 > > > >A cleaner way would be to just use uptime, as (correction) Jim said: > > > > uptime | cut -d, -f1-3 > > > > > >Since it's a perl list, and you asked how to do it with perl... > >Yes. Thank you for doing this. I apologize for the OT'ness of my reply. >:) Let me continue a perl tradition: > >perl -MShell -e 'chomp($uptime = uptime());($a,$b,$c) = >split(/,/,$uptime);print "$a,$b,$c\n"' > > > >There's probably a bazillion ways to accomplish this, but here's two ways: > > > >Example 1: > >---------- > >chomp($uptime = `uptime`); > >$uptime =~ s/^([\w\s:]+(,[\w\s:]+){2}).*$/$1/; > >print "$uptime\n"; > > > >Example 2: > >---------- > >chomp($uptime = `uptime`); > >$uptime = join(',',(split(/,/, $uptime, 4))[0,1,2]); > >print "$uptime\n"; > Merged mine up with Steven's. perl -MShell -e 'print join(",",(split(/,/,uptime(),4))[0,1,2]),"\n"' <-- very clean but kind of obfuscated >- - Jim > >Philosophy is for those who have nothing better to do than wonder >why philosophy is for those who have nothing better to do than... > > > >-----BEGIN PGP SIGNATURE----- >Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com> > >iQA/AwUBPCGMyNsnJUihkt7CEQJVQgCfYHCjMA9QjlJAUeneYhLl2iXRybEAn1wZ >aN9sZqQPawOepw57Dpmh1hlk >=rhdO >-----END PGP SIGNATURE----- > > >-- >To unsubscribe, e-mail: beginners-unsubscribe@perl.org >For additional commands, e-mail: beginners-help@perl.org - Jim Philosophy is for those who have nothing better to do than wonder why philosophy is for those who have nothing better to do than... To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5.1.0.14.0.20011220020635.0465b948>