From owner-freebsd-questions Thu Dec 20 19:23:55 2001 Delivered-To: freebsd-questions@freebsd.org Received: from Mail6.Carolina.rr.com (fe6.southeast.rr.com [24.93.67.53]) by hub.freebsd.org (Postfix) with ESMTP id 230E537B416 for ; Thu, 20 Dec 2001 19:23:49 -0800 (PST) Received: from snafu.enterit.com ([66.57.159.198]) by Mail6.Carolina.rr.com with Microsoft SMTPSVC(5.5.1877.687.68); Thu, 20 Dec 2001 01:43:48 -0500 Message-Id: <5.1.0.14.0.20011220020635.0465b948@mail.enterit.com> X-Sender: jconner@enterit.com@mail.enterit.com X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Thu, 20 Dec 2001 02:07:53 -0500 To: freebsd-questions@FreeBSD.ORG From: Jim Conner Subject: RE: extract uptime for linux box w/perl Cc: "Steven Hetland" , , "KeN ClarK" In-Reply-To: <5.1.0.14.0.20011220014711.02b7fce8@mail.enterit.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 > >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