I am trying to create a script to batch mark a group of users as privileged in RT. I found a script on the RT wiki for adding users to a group and giving them the privileged status, then removed the bits of it to do with adding to a group. The perl script I have remaining is:
#!/usr/bin/perl
# Usage: ./rt_set_privileged.pl <username>
use strict;
use lib "/var/www/ticket.ourcompany.com/lib";
use RT;
use RT::User;
use RT::Interface::CLI;
RT::LoadConfig();
RT::Init();
# Create RT User Object
my $user = new RT::User($RT::SystemUser);
# Instantiate the user object with the user passed as parameter
my $usertoadd = $ARGV[0];
$user->Load( $usertoadd );
# Set the privileged flag (1=privileged, 0=unprivileged)
$user->SetPrivileged(1);
exit 1
I have the users in a file, one username per line. I don't know perl as of yet, so I tried to create a little bash script to loop through the file and run the perl script once per name. The Bash script as it looks right now:
#!/bin/bash
touch commands.sh
cat usernames.txt | while read LINE ; do
N=$((N+1))
echo /home/chris/RT/bin/rt_set_privileged.pl \"$LINE\" >> commands.sh
/home/chris/RT/bin/rt_set_privileged.pl \"$LINE\"
perl /home/chris/RT/bin/rt_set_privileged.pl \"$LINE\"
perl -w /home/chris/RT/bin/rt_set_privileged.pl \"$LINE\"
eval /home/chris/RT/bin/rt_set_privileged.pl \"$LINE\"
perl "/home/chris/RT/bin/rt_set_privileged.pl $LINE"
done
echo "Processed $N users"
As you can see I have tried quite a few methods to get the command to run, but to no avail. The annoying thing is, I can take any of the commands from the commands.sh file afterwards and paste them straight into the terminal without a problem, this works fine. When they are run through the bash script though, I just get a bunch of these messages:
[Tue Sep 4 07:43:56 2012] [critical]: _AddMember called with a parameter that's not an integer. (/var/www/ticket.ourcompany.com/lib/RT/Group.pm:912)
[Tue Sep 4 07:43:58 2012] [warning]: Use of uninitialized value $principal in pattern match (m//) at /var/www/ticket.ourcompany.com/lib/RT/Group.pm line 970. (/var/www/ticket.ourcompany.com/lib/RT/Group.pm:968)
[Tue Sep 4 07:43:58 2012] [error]: Group::HasMember was called with an argument that isn't an RT::Principal or id. It's (undefined) (/var/www/ticket.ourcompany.com/lib/RT/Group.pm:973)
[Tue Sep 4 07:43:58 2012] [warning]: Use of uninitialized value $principal in pattern match (m//) at /var/www/ticket.ourcompany.com/lib/RT/Group.pm line 970. (/var/www/ticket.ourcompany.com/lib/RT/Group.pm:968)
[Tue Sep 4 07:43:58 2012] [error]: Group::HasMember was called with an argument that isn't an RT::Principal or id. It's (undefined) (/var/www/ticket.ourcompany.com/lib/RT/Group.pm:973)
[Tue Sep 4 07:43:58 2012] [warning]: Use of uninitialized value in concatenation (.) or string at /var/www/ticket.ourcompany.com/lib/RT/User.pm line 341. (/var/www/ticket.ourcompany.com/lib/RT/User.pm:341)
[Tue Sep 4 07:43:58 2012] [critical]: User is neither privileged nor unprivileged. something is drastically wrong. (/var/www/ticket.ourcompany.com/lib/RT/User.pm:341)
[Tue Sep 4 07:43:58 2012] [warning]: Use of uninitialized value $new_member in pattern match (m//) at /var/www/ticket.ourcompany.com/lib/RT/Group.pm line 911. (/var/www/ticket.ourcompany.com/lib/RT/Group.pm:911)
suggesting that the command is being run without any parameters. At this point I could have actually run the command once for each user in the time I have been trying to solve it, can anyone help?