Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: use getpwent to find users and delete them

by garcimo (Novice)
on May 18, 2018 at 13:48 UTC ( [id://1214848]=note: print w/replies, xml ) Need Help??


in reply to Re: use getpwent to find users and delete them
in thread use getpwent to find users and delete them

Hello sadly it does not work. executing this:
#!/usr/bin/perl use warnings; use strict; my $account = "tata"; my ( $name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell +, $expire ) = getpwent($account); if ( defined $uid ) { print "User $account uid=$uid. OK to delete user!\n"; } else { print "User $account does not exist...\n"; }
gives me errors:

syntax error at ./users_detect.pl line 9, near "($account" Execution of ./users_detect.pl aborted due to compilation errors.

if I do not put the getpwent($account) it compiles but always returns uid=0 whatever the account

Replies are listed 'Best First'.
Re^3: use getpwent to find users and delete them
by Corion (Patriarch) on May 18, 2018 at 13:56 UTC

    I think getpwent expects no parameter. It's unfortunate that it (or Perl) doesn't say so...

    Changing your code to use getpwnam instead works for me:

    my ( $uid ) = getpwnam($account);
Re^3: use getpwent to find users and delete them
by roboticus (Chancellor) on May 18, 2018 at 14:55 UTC

    garcimo:

    Sorry about that, I thought that I tested that, but it's obvious that I didn't. (Generally, I try to test my assumptions before converting a preview into an actual post, but it appears I made a mistake this time!)

    Good thing that Corion++ noticed the error and showed you the appropriate fix.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1214848]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-23 22:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found