我正在尝试创建一个脚本来批量标记一组用户在 RT 中具有特权。我在 RT wiki 上找到了一个脚本,用于将用户添加到组并赋予他们特权状态,然后删除了与添加到组有关的部分内容。我剩下的 perl 脚本是:
#!/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
我将用户放在一个文件中,每行一个用户名。我还不知道 perl,所以我尝试创建一个小 bash 脚本来遍历文件并为每个名称运行一次 perl 脚本。Bash 脚本现在的样子:
#!/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"
如您所见,我尝试了很多方法来运行命令,但无济于事。烦人的是,我可以在之后从 commands.sh 文件中获取任何命令并将它们直接粘贴到终端中而没有问题,这工作正常。但是,当它们通过 bash 脚本运行时,我只会收到一堆这样的消息:
[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)
暗示该命令在没有任何参数的情况下运行。在这一点上,在我试图解决它的时候,我实际上可以为每个用户运行一次命令,有人可以帮忙吗?