Creating a user using a simple perl script

Can someone tell me how to first see if a user name exists and if not how
to add a user? Once I get it adding a user I can figure out how to do all
the other user fields. I’m pretty good with perl, but the error that is
produced with the short/quick/dirty script I have is over my head.

By the way: I’ve added the lib dir for RT perl modules to the search path
for perl so its including RT::User (RT/User.pm) without a problem. However…

Here is my code:
#!/usr/bin/perl

use RT::User;
$NewUser = RT::User->new($RT::SystemUser);

         ( $Val, $Message ) = $NewUser->Create(
                               Name => "testdomain.com",
                               EmailAddress => 

"emailaddress@testdomain.com",
RealName => “Person J Smith”,
Password => “SuperMan”,
Privileged => 0,
Comments => ‘Autocreated by external
system.’
);

This produces this error:

./useradd.pl

at /usr/local/lib/perl5/5.8.0/RT/Base.pm line 54
RT::Base::CurrentUser(‘RT::User=HASH(0x813be40)’,‘undef’) called
at /usr/local/lib/perl5/5.8.0/RT/Record.pm line 67
RT::Record::_Init(‘RT::User=HASH(0x813be40)’,‘undef’) called at
/usr/local/lib/perl5/5.8.0/RT/User.pm line 57
RT::User::_Init(‘RT::User=HASH(0x813be40)’,‘undef’) called at
/usr/local/lib/perl5/site_perl/5.8.0/DBIx/SearchBuilder/Record.pm line 344
DBIx::SearchBuilder::Record::new(‘RT::User’,‘undef’) called at
/usr/local/lib/perl5/site_perl/5.8.0/DBIx/SearchBuilder/Record/Cachable.pm
line 21
DBIx::SearchBuilder::Record::Cachable::new(‘RT::User’,‘undef’)
called at ./useradd.pl line 4
Can’t call method “err” on an undefined value at
/usr/local/lib/perl5/5.8.0/RT/Base.pm line 54.

I’ve tried some more, but still can’t figure it out. If anyone knows how
to do this, please let me know.

At 11:48 PM 4/10/2003 -0700, Landon Stewart wrote: