LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-15-2014, 03:12 AM   #1
agarrett5
LQ Newbie
 
Registered: May 2012
Posts: 16

Rep: Reputation: Disabled
migrating aliases & groups from SME7 to Zimbra using a perl script


Hi,

I am trying to migrate SME aliases from SME7 server install to latest version of Zimbra OSE (8.0.7). Zimbra is sitting on top of Ubuntu server 12.04. The script is run on the SME server to generate zmprov commands to run in Zimbra.

I have downloaded a script from the research I have done to find out how to do this, but when the script is run I get errors.

The errors I get are:

Quote:
perl -w aliascript.pl
Name "main::alias" used only once: possible typo at aliascript.pl line 143 (#1)
(W once) Typographical errors often show up as unique variable names.
If you had a good reason for having a unique name, then just mention it
again somehow to suppress the message. The our declaration is
provided for this purpose.

NOTE: This warning detects symbols that have been used only once so $c, @c,
%c, *c, &c, sub c{}, c(), and c (the filehandle or format) are considered
the same; if a program uses $c only once but also uses any of the others it
will not trigger this warning.

Name "main:u" used only once: possible typo at aliascript.pl line 150 (#1)

The script that I am running is:

Quote:
#!/usr/bin/perl
use diagnostics;
################################################## ##############################
# $Id: aliases2zmprov,v 1.4 2007/03/07 22:18:56 dlbewley Exp $
#-------------------------------------------------------------------------------
# Description:
# Tool to create commands suitable for zmprov from a unix aliases file.
#
# Handles the case of an :include: construct.
# - Comments in include file are parsed as follows
# - "Foo" goes in LDAP description attribute, "Bar" in the displayname.
# # Description: foo
# # Name: Bar
#
# Handles the case of remote and multiple recipients by making a dist list.
# - A Zimbra alias must be associated with exactly one Zimbra account.
# - A Zimbra distribution list may contain users on remote hosts.
#
# See Also:
# http://wiki.zimbra.com/index.php?title=Bulk_Create
#
# Usage:
# ./aliases2zmprov /etc/aliases 1> aliases.zmp 2> aliases.err
# zmprov < aliases.zmp
#
################################################## ##############################

my @CNAME_SKIP= qw( ftp news postmaster root webmaster );
my @ALIAS_SKIP= qw( abuse mailer-daemon postmaster );
my @DISTRIBUTION_LISTS;
my $DOMAIN = 'abacuscover.com';
my $SOURCE_HOST = 'eserver';

use File::Basename;

while(<>) {
chomp;
s/#.*$//; # skip comments
next if /^\s*$/; # skip blank lines

my ($description,$display_name,@cnames);
my ($alias,$cname) = split(/:/,$_,2);

$alias =~ s/\s*//g;
# scrutinize the aliases
if (grep /^$alias$/, @ALIAS_SKIP) {
warn "skipping alias $alias -> $cname";
next;
}

$cname =~ s/\s*//g; # remove all spaces

# scrutinize the canonical names
if ($cname =~ m/:include:/) {
(($description, $display_name, $cnames_ref) =
parse_include($cname)) || next;
@cnames = @{$cnames_ref};
}
if ($cname =~ m/,/) {
# multiple recipients make this a list instead of an
alias
@cnames = split(/,/,$cname);
}

# if more than one cname then it is a dist list
if (length($cnames[0])) {
print "\n";
print "createDistributionList $alias\@$DOMAIN\n";
push (@DISTRIBUTION_LISTS, $alias);
if ($display_name) {
print "modifyDistributionList $alias\@$DOMAIN
displayname \"$display_name\"\n";
$display_name = undef;
}
if ($description) {
print "modifyDistributionList $alias\@$DOMAIN
description \"$description\"\n";
$description = undef;
}
foreach my $member (@cnames) {
# skip aliases to certain users
if (grep /^$member$/, @CNAME_SKIP) {
warn "skipping cname $member <- $alias";
next; # go to next member
}
# A Zimbra distribution list may contain users on
remote hosts.
if ($member =~ m/\@/) {
print "addDistributionListMember
$alias\@$DOMAIN $member\n";
} else {
print "addDistributionListMember
$alias\@$DOMAIN $member\@$DOMAIN\n";
}
}
print "\n";
@cnames=();
next; # go to next line of aliases file
}

# skip aliases to certain users
if (grep /^$cname$/, @CNAME_SKIP) {
warn "skipping cname $cname <- $alias";
next;
}
if ($cname =~ m/\/|\|/) {
# alias to a file or a program. don't try to
accomodate
warn "WARNING skipping cname $cname <- $alias it is a
file or pipe";
next;
}

# A Zimbra alias must be associated with exactly one
Zimbra account.
if ($cname =~ m/\@/) {
# alias to remote host. this could be created as a
dist list with 1 member
# that seems undersirable though.
print "\n";
print "createDistributionList $alias\@$DOMAIN\n";
print "addDistributionListMember $alias\@$DOMAIN
$cname\n";
print "\n";
next; # go to next line of aliases file
}
# is the cname a distribution_list already?
if (grep /^$cname$/, @DISTRIBUTION_LISTS) {
print "addDistributionListAlias $cname\@$DOMAIN
$alias\@$DOMAIN\n";
}
# are we sure that account $cname\@$DOMAIN exists?
else {
print "addAccountAlias $cname\@$DOMAIN
$alias\@$DOMAIN\n";
}
}

# read an included alias file. commens with Name: and
Description:
# are placed into LDAP attributes for the list
sub parse_include {
my $cname = shift;
my @cnames;
# need to pull in contents of file and make a dist
# list instead of an alias
my $fullfile = $cname;
$fullfile =~ s/:include://;
my ($file,$path) = fileparse($fullfile);
if (! -e $file) {
warn "WARNING skipping $alias -> $cname Please run
'scp $SOURCE_HOST:$fullfile .'";
return; # go to next line of aliases file
} else {
# process include file
open(F,$file) || warn "Can not read $file";
while (<F>) {
chomp;
(m/#\s*Department:*\s*(.*)/) && ($ou = $1); #
can't make use of this in zmprov mdl
if (m/#\s*Description:*\s*(.*)/) {
$description = $1;
$description =~ s/"/'/g; # don't blow our
command line
}
if (m/#\s*Name:*\s*(.*)/) {
$display_name = $1;
$display_name =~ s/"/'/g; # don't blow our
command line
}
s/#.*$//; # skip comments
next if /^\s*$/; # skip blank lines
push @cnames, $_;
}
}
return $description, $display_name, \@cnames;
}
I am assuming theres something within this I need to change as regards to tailoring it to the SME install? I'm not a coder at best of times! I suspect its something very simple I am missing here. Looks to me like theres a couple of things that need declaring.
 
Old 05-16-2014, 08:19 PM   #2
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Try that

Whups, forgot to put your #!/bin/perl call back in there, sorry

Code:
#!/usr/bin/perl
use diagnostics;
################################################## ##############################
# $Id: aliases2zmprov,v 1.4 2007/03/07 22:18:56 dlbewley Exp $
#-------------------------------------------------------------------------------
# Description:
# Tool to create commands suitable for zmprov from a unix aliases file.
#
# Handles the case of an :include: construct.
# - Comments in include file are parsed as follows
# - "Foo" goes in LDAP description attribute, "Bar" in the displayname.
# # Description: foo
# # Name: Bar
#
# Handles the case of remote and multiple recipients by making a dist list.
# - A Zimbra alias must be associated with exactly one Zimbra account.
# - A Zimbra distribution list may contain users on remote hosts.
#
# See Also:
# http://wiki.zimbra.com/index.php?title=Bulk_Create
#
# Usage:
# ./aliases2zmprov /etc/aliases 1> aliases.zmp 2> aliases.err
# zmprov < aliases.zmp
#
################################################## ##############################
my @CNAME_SKIP= qw( ftp news postmaster root webmaster );
my @ALIAS_SKIP= qw( abuse mailer-daemon postmaster );
my @DISTRIBUTION_LISTS;
my $DOMAIN = 'abacuscover.com';
my $SOURCE_HOST = 'eserver';

use File::Basename;

while(<>) {
chomp;
s/#.*$//; # skip comments
next if /^\s*$/; # skip blank lines

my ($description,$display_name,@cnames);
my ($alias,$cname) = split(/:/,$_,2);

$alias =~ s/\s*//g;
# scrutinize the aliases
if (grep /^$alias$/, @ALIAS_SKIP) {
warn "skipping alias $alias -> $cname";
next;
}

$cname =~ s/\s*//g; # remove all spaces

# scrutinize the canonical names
if ($cname =~ m/:include:/) {
(($description, $display_name, $cnames_ref) =
parse_include($cname)) || next;
@cnames = @{$cnames_ref};
}
if ($cname =~ m/,/) {
# multiple recipients make this a list instead of an alias
@cnames = split(/,/,$cname);
}

# if more than one cname then it is a dist list
if (length($cnames[0])) {
print "\n";
print "createDistributionList $alias\@$DOMAIN\n";
push (@DISTRIBUTION_LISTS, $alias);
if ($display_name) {
print "modifyDistributionList $alias\@$DOMAIN
displayname \"$display_name\"\n";
$display_name = undef;
}
if ($description) {
print "modifyDistributionList $alias\@$DOMAIN
description \"$description\"\n";
$description = undef;
}
foreach my $member (@cnames) {
# skip aliases to certain users
if (grep /^$member$/, @CNAME_SKIP) {
warn "skipping cname $member <- $alias";
next; 
# go to next member
}
# A Zimbra distribution list may contain users on remote hosts.
if ($member =~ m/\@/)
{
print "addDistributionListMember $alias\@$DOMAIN $member\n";
}
else 
{
print "addDistributionListMember $alias\@$DOMAIN $member\@$DOMAIN\n";
}
}
print "\n";
@cnames=();
next; # go to next line of aliases file
}

# skip aliases to certain users
if (grep /^$cname$/, @CNAME_SKIP) {
warn "skipping cname $cname <- $alias";
next;
}
if ($cname =~ m/\/|\|/) {
# alias to a file or a program. don't try to accomodate
warn "WARNING skipping cname $cname <- $alias it is a
file or pipe";
next;
}

# A Zimbra alias must be associated with exactly one Zimbra account.
if ($cname =~ m/\@/) {
# alias to remote host. this could be created as a dist list with 1 member
# that seems undersirable though.
print "\n";
print "createDistributionList $alias\@$DOMAIN\n";
print "addDistributionListMember $alias\@$DOMAIN
$cname\n";
print "\n";
next; # go to next line of aliases file
}
# is the cname a distribution_list already?
if (grep /^$cname$/, @DISTRIBUTION_LISTS) {
print "addDistributionListAlias $cname\@$DOMAIN
$alias\@$DOMAIN\n";
}
# are we sure that account $cname\@$DOMAIN exists?
else {
print "addAccountAlias $cname\@$DOMAIN
$alias\@$DOMAIN\n";
}
}

# read an included alias file. commens with Name: and
Description:
# are placed into LDAP attributes for the list
sub parse_include {
my $cname = shift;
my @cnames;
# need to pull in contents of file and make a dist
# list instead of an alias
my $fullfile = $cname;
$fullfile =~ s/:include://;
my ($file,$path) = fileparse($fullfile);
if (! -e $file) {
warn "WARNING skipping $alias -> $cname Please run
'scp $SOURCE_HOST:$fullfile .'";
return; # go to next line of aliases file
} else {
# process include file
open(F,$file) || warn "Can not read $file";
while (<F>) {
chomp;
(m/#\s*Department:*\s*(.*)/) && ($ou = $1); 
#can't make use of this in zmprov mdl
if (m/#\s*Description:*\s*(.*)/) {
$description = $1;
$description =~ s/"/'/g; 
# don't blow our command line
}
if (m/#\s*Name:*\s*(.*)/) {
$display_name = $1;
$display_name =~ s/"/'/g;
# don't blow our command line
}
s/#.*$//; # skip comments
next if /^\s*$/; # skip blank lines
push @cnames, $_;
}
}
}
return $description, $display_name, \@cnames;

Last edited by dijetlo; 05-16-2014 at 08:51 PM. Reason: completeness
 
  


Reply

Tags
sme, ubuntu, zimbra



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl script to rationalize /etc/groups scottmusician Programming 2 06-25-2013 02:05 AM
[SOLVED] bash & perl - script adjustment webhope Programming 10 05-24-2010 06:51 AM
perl not recognized by zimbra installer bluethundr Linux - Newbie 2 05-14-2010 12:58 PM
Zimbra server and perl problem Storm16 Linux - Server 0 11-06-2006 12:55 PM
Mail script with Perl & Postfix Bladez Programming 2 02-14-2004 09:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration