#!/usr/local/bin/perl use strict; use warnings; use Term::ReadKey qw(ReadMode ReadLine); use IPC::System::Simple qw(system); my $choice=0; GETCHOICE: { print "Admin Menu\n"; print "To add a user, press 1\n"; print "To delete a user, press 2\n"; print "To add a group, press 3\n"; print "To delete a group, press 4\n"; print "To exit this menu, press 5\n"; print "Please choose an option: "; chomp($choice=<STDIN>); redo GETCHOICE if $choice < 1 || $choice > 5; } print "You chose option: $choice\n"; if($choice == 1) { my $nUsername; GETUSER: { print "What is new users name? "; chomp($nUsername=<STDIN>); # check that new user name is a string if($nUsername!~/^[A-Za-z0-9]+$/) { print "New username must be a string.\n"; redo GETUSER; } } # check to see if user exists if(defined getpwnam($nUsername)) { print "User exists\n"; } else { ## FIXME delete "echo" system("echo","/usr/sbin/adduser","--home", "/home/$nUsername","--gecos",$nUsername); # get new user password my ($nPassword,$nPasstest); GETPASS: { ReadMode("noecho"); print "Please add password: "; chomp($nPassword=ReadLine(0)); print "\n"; print "Please re-enter password: "; chomp($nPasstest=ReadLine(0)); print "\n"; ReadMode("restore"); redo GETPASS if $nPassword ne $nPasstest; } print "Please enter group for user: "; chomp(my $nGroup=<STDIN>); # add user to group if(defined getgrnam($nGroup)) { # check to see is group exists print "$nGroup already exists\n"; # add user to group system("echo","groupadd",$nGroup); } else { # if group does not exist create group system("echo","groupadd",$nGroup); print "$nGroup has been added.\n"; } } }
In reply to Re: unix to perl questions
by Anonymous Monk
in thread unix to perl questions
by deyaneria
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |