#!/usr/bin/perl # retrainAll.osbf-lua - Invoke retrainUser for all users, or a subset # # Author: # Steve Pellegrin (spellegrin at convoglio dot com) # # History: # 1.0 2006-August-6 Original code # 1.1 2008-September-29 Rework command line option processing # # Usage: # retrainAll.osbf-lua [--verbose] [--quiet] [--force] # # Description: # This script can be run manually, but it probably makes more sense to run it # periodically as a cron job. Each time it runs, the script iterates over # each user account, invoking retrainUser on that account. The set of users # processed is configurable in a number of ways (see Configuration parameters, below). # # Note that the script must be run from an account that can invoke retrainUser # on behalf of user accounts. This probably imples root. use strict; # to catch stupid errors use Getopt::Long; use Pod::Usage; # ---------- Configuration ------------------------------------------ # There are three ways to collect user home directories: # 1. Assume that all users have directories inside of # some "base" directory (typically /home). # 2. Collect home directories from a range of UID values. # 3. Collect home directories from a list of UID values. # # ONE of $baseDir or @uidList should be defined. # Case #1 # User directories (and only user directories) are found here my $baseDir = "/home"; #my $baseDir = undef; # The list of UIDs to examine. # Case #2: Specify a range of values n..m # Case #3: Specify a list of discrete values (a, b, c, d) # my @uidList = 500..2000; #my @uidList = 1000; #my @uidList = (1006..1014); my @uidList = undef; # Location of retrainUser my $retrainUserCmd = "/usr/local/bin/retrainUser.osbf-lua"; # Location of sudo with necessary flags. my $sudoCmd = "/usr/local/bin/sudo -H"; # ---------- End of Configuration ----------------------------------- # Pre-check command line arguments. my @args = @ARGV; GetOptions ( 'verbose' => \(my $verbose = ''), 'quiet' => \(my $quiet = ''), 'force' => \(my $force = ''), 'help' => \(my $help = ''), ) or pod2usage(2); # Print help text and exit if requested. pod2usage(1) if $help; # Collect user names and home directories. my @users = defined($baseDir) ? collectBasedUserInfo() : collectUIDUserInfo(); foreach my $user (@users) { my $cmd = "$sudoCmd -u $user $retrainUserCmd @args"; my $output = `$cmd`; print $output; } sub collectBasedUserInfo { my @list; # Read in all the user directories in the base directory, # e.g., /home/alice, /home/bob, /home/charles opendir(DIR,$baseDir); while (my $userDir = readdir(DIR)) { next if ($userDir =~ /^\./); push (@list, $userDir); } closedir(DIR); @list; } sub collectUIDUserInfo { my @list; foreach my $uid (@uidList) { my $user = (getpwuid $uid)[0]; if (defined($user)) { push (@list, $user); } } @list; } __END__ =head1 NAME retrainAll.osbf-lua - Retrain all user accounts =head1 SYNOPSIS retrainAll.osbf-lua [options] =head1 OPTIONS =over 8 =item B<--verbose> Print verbose output =item B<--quiet> Print minimal output =item B<--force> Reinitialize cfc files =item B<--help> Print this text =back =cut