#!/usr/bin/perl use strict; use warnings; sub trim($); sub ltrim($); sub rtrim($); my $SCRIPT_NAME = "pd_getusersingrps.pl"; my $pduserid; my $pdpasswd; my $sec = 0; my $min = 0; my $hour = 0; my $mday = 0; my $mon = 0; my $year = 0; my $wday = 0; my $yday = 0; my $isdst = 0; my $hostname = ""; my $envOS = ""; my $pdversion = ""; my @x_groups = ("group1", "group2", "group3", "group4", "group5"); my $xgrp = ""; my $numOfGroups = 0; my @x_users = (); my $xusr = ""; my $numOfUsers = 0; if (@ARGV == 2) { $pduserid = $ARGV[0]; $pdpasswd = $ARGV[1]; ($sec,$min,$hour,$mday,$mon,$year,$wday, $yday,$isdst) = localtime(time); printf("%4d-%02d-%02d %02d:%02d:%02d\n", $year+1900,$mon+1,$mday,$hour,$min,$sec); foreach $xgrp (@x_groups) { chomp($xgrp); $xgrp = trim($xgrp); @x_users = `pdadmin -a $pduserid -p $pdpasswd group show-members $xgrp | sort`; $numOfUsers = @x_users; if ($numOfUsers > 0) { print("There are $numOfUsers users in group: $xgrp\n"); foreach $xusr (@x_users) { chomp($xusr); $xusr = trim($xusr); print("$xusr\n"); } print("\n"); } else { print("There are no users in group: $xgrp\n\n"); } } } else { print("This script requires two parameters - TAM id and TAM passsword, for example:\n"); print("perl $SCRIPT_NAME sec_master password\n"); } # trim functions from www.somacon.com/p114.php # Perl trim function to remove whitespace from the start and end of the string sub trim($) { my $string = shift; $string =~ s/^\s+//; $string =~ s/\s+$//; return $string; } # Left trim function to remove leading whitespace sub ltrim($) { my $string = shift; $string =~ s/^\s+//; return $string; } # Right trim function to remove trailing whitespace sub rtrim($) { my $string = shift; $string =~ s/\s+$//; return $string; }