It seems like you don't have much experience writing Perl scripts, right? That's no problem, here's an example that I hope is useful for you.
Please check out the following snippet. Please note that it assumes it is placed in the /opt/otrs/bin directory. If you want to have it somewhere else, modify the line that says
use lib accordingly.
Code: Select all
#!/usr/bin/perl -w
# --
# otrs.printUser - Prints some user data
# Copyright (C) 2001-2010 xxx, http://otrs.org/
# --
# $Id$
# --
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU AFFERO General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# or see http://www.gnu.org/licenses/agpl.txt.
# --
use strict;
use warnings;
# use ../ as lib location
use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);
use lib dirname($RealBin) . "/Kernel/cpan-lib";
use Getopt::Std;
use Kernel::Config;
use Kernel::System::Encode;
use Kernel::System::Log;
use Kernel::System::Main;
use Kernel::System::DB;
use Kernel::System::Time;
use Kernel::System::User;
my %Opts = ();
getopt( 'h', \%Opts );
if ( $Opts{h} || !$ARGV[0]) {
print "otrs.printUser - print some user details\n";
print "Copyright (C) 2001-2010 xxx, http://otrs.org/\n";
print "usage: otrs.printUser [username] \n";
exit 1;
}
# create common objects
my %CommonObject = ();
$CommonObject{ConfigObject} = Kernel::Config->new(%CommonObject);
$CommonObject{EncodeObject} = Kernel::System::Encode->new(%CommonObject);
$CommonObject{LogObject} =
Kernel::System::Log->new( %CommonObject, LogPrefix => 'otrs.printUser', );
$CommonObject{MainObject} = Kernel::System::Main->new(%CommonObject);
$CommonObject{TimeObject} = Kernel::System::Time->new(%CommonObject);
$CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject);
$CommonObject{UserObject} = Kernel::System::User->new(%CommonObject);
my $User = shift;
# fetch the data for the user
my %User = $CommonObject{UserObject}->GetUserData( User => $User, );
if ( !%User ) {
print "User $User does not exist.\n";
exit 1;
}
print "User:\t\t$User\n";
print "First name:\t$User{UserFirstname}\n";
print "Last name:\t$User{UserLastname}\n";
print "Email:\t\t$User{UserEmail}\n";
exit 0;