Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!wuarchive!emory!gatech!mcnc!uvaarpa!mmdf From: frech@mwraaa.army.mil (Norman R. Frech CPLS) Newsgroups: comp.lang.perl Subject: passwd/$home/who Message-ID: <1990Nov20.164319.7326@uvaarpa.Virginia.EDU> Date: 20 Nov 90 16:43:19 GMT Sender: mmdf@uvaarpa.Virginia.EDU (Uvaarpa Mail System) Reply-To: frech@mwraaa.army.mil Organization: The Internet Lines: 42 I am having problems with the following code. What I am trying to do is slurp the password file fields $login,$home into a varible, run who, and then grep the $home out of my variable for each person logged on. I figured it would be faster to grab the password file one time in the beginning instead of opening it for each person out of the who. I have tried various search approaches and they either return a 1 or something completely erroneous. It is evident I do not have a clue. Help. *** cut here *** eval "exec /usr/local/bin/perl -S $0 $*" if $running_under_some_shell; # this emulates #! processing on NIH machines. # (remove #! line above if indigestible) open(HOME, "/etc/passwd") || die "Can't access passwork file: $!\n"; while () { ($login,$passwd,$uid,$gid,$gcos,$home,$shell) = split(/:/); $pass .= "$login:$home\n"; } close HOME; print $pass; print "\n"; # open an input pipe to run who open(WHO, "who |") || die "Can't run who: $!\n"; ($wday, $mo, $today) = split(' ', `date`); while () { chop; ($user, $tty, $month, $mday, $time) = split; print $user; print "\n"; # grab the home directory from $pass @foo = grep($pass,$user); print @foo; print "\n"; }