#!/opt/bin/perl # ######################################################################### # # # Programm zur Erzeugung einer Kopie der aktuellen Passwd- und Group- # # Datei, unabhaengig vom NIS-System (Yellow Pages) # # # ######################################################################### # # # Version 1.0 - Written 15.04.95 by Steffen Beyer # # # ######################################################################### # # # Copyright (C) 1995 by software design & management GmbH & Co. KG # # # ######################################################################### # # Einige wichtige Defaulteinstellungen: # $version = 'Version 1.0'; # $self = $0; # if ($self =~ /^.*\/([^\/]+)$/) { $self = $1; } # $PWD_FILE = '/g/sysadm/etc.passwd.old'; $GRP_FILE = '/g/sysadm/etc.group.old'; # $pwd_file = $PWD_FILE; $grp_file = $GRP_FILE; # # Optionen aus der Kommandozeile ueberpruefen und uebernehmen: # while (@ARGV) { $_ = shift; if (/^-p$/) { $pwd_file = shift; } elsif (/^-g$/) { $grp_file = shift; } elsif (/^-p\S+$/) { $pwd_file = substr($_,2); } elsif (/^-g\S+$/) { $grp_file = substr($_,2); } elsif (/^-\?$/) { $help = 1; } elsif (/^-h$/) { $help = 1; } else { $error = 1; unless (defined $option) { $option = $_; } } } # # Hilfe gewuenscht? # if ($help) { print <<"@@"; '$self' $version Usage: $self [ ]* where is one of the following: -p Explicitly specifies the name of the copy of the passwd-file (default is '$PWD_FILE') -g Explicitly specifies the name of the copy of the group-file (default is '$GRP_FILE') (white space between option letter and file name is optional) -h Produces this help screen -? Produces this help screen @@ exit; } # # Unbekannte Option gefunden? # if (($error) && ($option)) { die "Error: Unknown option '$option' encountered!\nEnter '$self -h' for help.\n"; } # # Aktuelle Passwort-Datei kopieren: # open(PWD, ">$pwd_file") || die "Can't open '$pwd_file': $!\n"; # setpwent; # while (($user,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) = getpwent) { printf(PWD "%s:%s:%s:%s:%s:%s:%s\n", $user,$passwd,$uid,$gid,$gcos,$dir,$shell); } # endpwent; # close(PWD); # # Aktuelle Gruppen-Datei kopieren: # open(GRP, ">$grp_file") || die "Can't open '$grp_file': $!\n"; # setgrent; # while (($group,$passwd,$gid,$members) = getgrent) { $members =~ tr/ /,/; printf(GRP "%s:%s:%s:%s\n", $group,$passwd,$gid,$members); } # endgrent; # close(GRP); # # Bestaetigung ausgeben: # printf("\n'%s' %s\n\n", $self, $version); printf("Name of copied passwd file = '%s'\n", $pwd_file); printf("Name of copied group file = '%s'\n\n", $grp_file); # # Fertig. #