I'm looking for a fast way to import customer users into otrs (ticket system) I have an export from Active Directory with:

firstname lastname password email username

There is a script in the otrs/bin folder with this script:

otrs.AddCustomerUser.pl [-f firstname] [-l lastname] [-p password] [-g groupname] [-e email] [-c CustomerID] username
if you define -g with a valid group name then the user will be added that group

So now I would like to have a bash script that reads each line and execute the otrs.AddCustomerUser.pl script with the variables / input from users.txt I think it wil be something with awk but my brain cant figure it out. I did find lots of scripts that do almost the same, but I just cant find the right way to make it work.

The users.txt file is formated like


This is the code I got now, but it's not working.


while read
        firstname=$( echo $line | cut -f1 )
        lastname=$( echo $line | cut -f2 )
        password=$( echo $line | cut -f3 )
        email=$( echo $line | cut -f4 )
        user=$( echo $line | cut -f5 )
do /opt/otrs/bin/otrs.AddCustomerUser.pl -f $firstname -l $lastname -p $password -e $email -c CUSTOMER $user

done < /root/tabdelimited.csv
  • I must be missing something. Can't you just iterate over the lines in the AD dump and run that utility on them? Are you asking how to check if the user is already in OTRS?
    – Bratchley
    Commented Dec 17, 2014 at 15:17
  • Here is a resource for iterating over lines in a file in bash. You can use cut to extract each field value from each line. Not sure what OTRS provides to check whether a given user exists, though.
    – Bratchley
    Commented Dec 17, 2014 at 15:23
  • i'm installing a new otrs instance. so now it's completly empty. there are no customer_users in the mariadb database. the addcustomer script will add the users to the database. i need to find a way to make each colum in the txt file a variable wich i then can use to run the otrs script. Commented Dec 17, 2014 at 15:23
  • That's why I was suggesting you use cut. For example $firstName=$( echo $line | cut -f1 )
    – Bratchley
    Commented Dec 17, 2014 at 15:30
  • Ok. tnx. im not at work anymore so i will try tomorrow. Commented Dec 17, 2014 at 19:56

2 Answers 2


It is very easy to do with Bash. Your could extend from the following idea:

while read firstname lastname password email username; do \
    otrs.AddCustomerUser.pl -p password ...; done

Replace the dots with the complete command-line.

  • i did try some code, but i don't get it to work yet. the code i used is added to my first post Commented Dec 18, 2014 at 12:52
  • The line variable in your snippet is most probably uninitialized. It would essentially do, echo | cut -f1 and get you to read firstname= lastname= ... giving error. Basically, you don't need the multiple echo-cut invocations.
    – pdp
    Commented Dec 18, 2014 at 13:03

Ok. Thanks all. especially @pdp. Your code was almost spot on for me. The exact code i used is below ... maybe for the next otrs migrater:

while read First Last Pw Email User; do
    /opt/otrs/bin/otrs.AddCustomerUser.pl -f $First -l $Last -p $Pw -e $Email -c CustomerCompany $User
done < /root/tabdelimited.csv

Don't know if the IFS=$'\t' is needed, it should define tabs are used in the csv file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .