[ILUG] Re: Need help with Perl script

Phil phil at redbrick.dcu.ie
Tue May 2 14:46:07 IST 2000


Tina Marie's [TinaDp6 at netscape.net] 22 lines of dribble included:
> 
> 
> I need to have the number of users printed out within my perl script.
> 
>   I know the UNIX command is w -h | wc -l
That doesn't work if users are logged in multiple times. 
w | awk '{print $1}' | sort | uniq | wc -l
(sort -u saves a pipe on some systems)

>   But how do I get it to print out like the sample below?
> 
> 
>   There are 7 users logged on the system.
This sounds more of a shell scripty way of doing things than actually needing
to do it in perl. However if what you're looking for is something like

#!/usr/bin/perl
$blah = system("w | awk '{print $1}' | sort | uniq | wc -l");
print "There are $blah users logged on";

Probably a far better way in perl is
$var = `who`;
Then parsing your input here using perl. This is more optimal and a far better
reason to use perl than shell scripting after all. I'm not a big believer in
using system calls in perl at all. 
Phil.




More information about the ILUG mailing list