Friday, May 21, 2004
Extracting values from pdbedit output
The verbose output from pdbedit is kinda screwy; here's some code to pluck out specific values- I've wanted to be able to grab "Account desc" for sorting users as I migrate them.
The verbose output from pdbedit is kinda screwy; here's some code to pluck out specific values- I've wanted to be able to grab "Account desc" for sorting users as I migrate them.
#!/usr/bin/perl
#parse a verbose pdbedit record
#put record keys and values into a hash
#pdbedit command- change for your system.
$pdbedit = '/usr/local/sbin/pdbedit -s /etc/samba/pdc/smb.conf';
foreach $username (@ARGV){
open (UREC, "$pdbedit -v $username |");
foreach (){
chomp;
#split key from value
@line = split(/: /);
#looks like the values are formatted with whitespace
#take out the leading whitespace
$line[1] =~ s/^\s+//;
$urec{$line[0]} = $line[1];
}
close (UREC);
#example output
print "$urec{'NT username'}\n";
print "$urec{'Full Name'}\n";
print "$urec{'Account desc'}\n";
}