Linux -сборник рецептов

Глава 8 Управление пользователями и группами

Листинг 8.2 {продолжение)

g_ent=$(getent group "$1" 2>&-) if [ -z "$g_ent" ]; then echo >&2 "warning: $1: group not found" continue fi members=${g_ent##*:} gid=${g_ent%:*} gid=${gid##*:} echo "$members" | tr '.' ' ' getent passwd | awk -F: '{if ($4 == '$gid') { print $1 } }' shift done } # Основной код group_mode=; verbose=; all_mode=; simulate=; eol=; while [ -z "$eol" ]; do case "$1" in -g) group_mode=1; shift ;; -v) verbose=1; shift ;; -a) all_mode=1; shift ;; -n) simulate=true; verbose=1; shift ;; -M) mass_out=1; shift ;; # we're called from mass_useradd -h | -? | --help) usage ;; --) eol=1; shift ;; -*) short_usage ;; *) eol=1 ;; esac done # Настройка безопасного окружения и каталога для текстовых файлов. # предназначенных для вывода на печать. PATH=/usr/sbin:/usr/bin:$PATH umask 077 mkdir -р $text_file_dir cd $text_file_dir

processed=0 for u in $(get_users "$@"); do vecho -n "generating password for $u..." pass=$(randompass) echo "$u:$pass" | eval $simulate chpasswd vecho -n "." eval $simulate chage -M $pass_expire -d 2003-01-01 $u vecho -n "."

rm -f $u.passwd.txt echo > $u.passwd.txt "\ ---------------------------------------------------------------------- Login name: $u Password: $pass Please log in and change your password: the system should prompt you to do this when you log in. You can change your 8.18. Серийная замена паролей

password at any time with the 'passwd' command. Choose a strong password - everyday words, birthdays, names of people or animals, all these are too easy to guess. Also, DO NOT give your password to anyone, ever. The IT staff will never ask you for your password, and neither should anyone else. You will be held responsible for all activity done via your account. ----------------------------------------------------------------------" printf >> $log_file "$(date) %-12s %s\\n" $u $pass vecho "$pass" if [-n "$mass_out" ]; then uid=$(getent passwd $u | cut -f3 -d:) echo -e "$u\\t$pass\\t$uid" fi processed=$(expr $processed + 1) done

if [ $processed -gt 0 ]; then test -z "$mass_out" && echo >&2 "$processed password(s) reset - see $text_file_dir/$log_file" else echo >&2 "no users specified - see '$prog -h' for help" fi См. также

bash(1), pwgen(1); домашняя страница программы pwgen (

Начало  Назад  Вперед

Книжный магазин