Hi Scott,
> Thanks for the reply. My goal is to create a script for
creating new users
> that automates all of the individual tasks that are
starting to get
> tedious. This is also a good opportunity for me to get
a handle on
> scripting in general with Perforce.
Indeed - sounds like a great place to start.
> I come from an extensive background in ClearCase. Over
the years I've
> developed many scripts used by both myself as an
administrator and by my
> user base. They have been spoiled with all of the
things they can do with
> my scripts. So, they expect the same as we transition
over to Perforce.
I doubt they'll be disappointed: anything you can do from
the command line,
you can do in a script.
> Back to the script... I want to take a users full name
and do the
> following:
>
> 1) Create a user based on the full name as lowercase
<first initial><last
> name>. 2) Set the new users Email address to include
our domain name.
> 3) Initialize user password. ( We use strong passwords.
Eventual LDAP
> authentication. ) 4) Add the user to the primary users
group.
> 5) Add the user to any other groups as needed.
>
> Any input on the remaining steps.
Sure. On step 3, you'll need to use something like this:
$p4->SetInput( [ $newpass, $newpass ] );
$p4->Run( "passwd", $username );
This is because the dialog for a user who has an existing
password is a little
different from setting an initial password (there's no
prompt for the
existing password), and P4::Password() doesn't handle that.
It may do in
future, but it doesn't now.
On steps 4 and 5, here's an example:
------------------------ cut
--------------------------------
#!/usr/bin/perl
use P4;
my $p4 = new P4;
$p4->ParseForms();
$p4->Connect() or die( "Can't connect to
Perforce" );
# Create the new user
my $user = $p4->FetchUser( 'TestUser' );
$user->{ 'Email' } = 'tony perforce.com';
$user->{ 'FullName' } = 'Test User';
$p4->SaveUser( $user, "-f" );
# Add the user to the group, creating it if necessary
my $group = $p4->FetchGroup( 'somegroup' );
$group->{ 'Users' } = [] unless defined $group->{
'Users' };
push( {$group->{ 'Users' }}, $user->{ 'User' } );
$p4->SaveGroup( $group );
------------------------ cut
--------------------------------
Hope that helps!
Tony
_______________________________________________
p4perl mailing list
p4perl perforce.com
http://maillist.perforce.com/mailman/listinfo/p4perl
|