On 11/9/05, Ryan Frantz <[EMAIL PROTECTED]> wrote:
>
>
> > -----Original Message-----
> > From: Rob.Savino [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, November 09, 2005 1:50 PM
> > To: [email protected]
> > Subject: help with matching
> >
> >
> > I'm working on a simple script to get a list of users who do not exist
> >
> > while (<>) {
> > $user = system("echo $_");
Why are you doing this??if you want to save $_ into the variable
$user, just do it:
$user = $_;
You probably want to chomp it, too; I doub't any of your users are
named, say "rob\n":
$user = chomp($_);
> > $result = system("dsquery user -samID $_");
> > }
> > if (!$result) {
>
> 'system' will always return the exit status of whatever program you
> called. So $result is always set (zero _and_ non-zero statuses).
> Basically, if it fails or succeeds your script will output the user
> name. You'll need to check the status that $result is set to and code
> for that.
>
> > print "$user\n";
> > }
> >
Or to put it another way, see perlddoc -q "output of a command".
You're looking for backticks.
> Four things to note:
>
> 1. use warnings;
> 2. use strict;
> 3. Scope your variables
> 4. Search CPAN for a module that will help with MS Active Directory
> queries instead of performing system calls. You'll be happy you did.
>
> ry
>
> > Here is my problem,
> >
> > dsquery user -samID should return nothing if a user does not exist. I
> > was hoping the script would print $user only if there was no $result
> > from dsquery user -samID. However, not only does it print every $user
> > regardless of the was not $result, it also prints every $result.
> >
> > Can someone tell me why this is?
> >
Sure.
$user = system("echo $_");
tells the system to print every user to standard output. Then is saves
the result of "echo"--0 if the line printed--to $user.
$result = system("dsquery user -samID $_");
queries the system and saves the return value of the command--0 if the
command executed--to $result. And since 0 is a false value in Perl,
if (!$result) {
print "$user\n";
}
prints $user every time.
We're here to help, but if this is sounding new to you, you really
need to pick up a copy of Learning Perl (O'Reilly) and read it. Don't
make calls to system until you know what you're doing. It's a great
way to get into trouble fast.
HTH,
-- jay
--------------------------------------------------
This email and attachment(s): [ ] blogable; [ x ] ask first; [ ]
private and confidential
daggerquill [at] gmail [dot] com
http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org
values of β will give rise to dom!