The error arrives from option 'a' it asks for user name, check in the system but does not return the correct answer please help me with it.
or if you have better way of doing it would you please mind to tell me..
thanks..
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/perl -w
- #use Getopt::Std;
- print "\nWelcome to the New Era!! Assignment 1!! \n\nFor help to run program press h !!\n\n ";
- #
- # Take input from user
- #
- print "\nEnter the Option --> : ";
- chomp ($option = <>);
- while($option ne "q")
- {
- #
- # Adding user option
- #
- if($option eq "a")
- {
- print "\n\n--- Add User Menu --- \n\n";
- print "\nEnter User Name --> : ";
- chomp ($userName = <>);
- #
- #Checking for the user if its exist in the UNIX
- #
- $chkrs = 'grep -c -w $username /etc/passwd'; # grep : search files for lines, match given pattern
- print "\n User $chkrs \n";
- if($chkrs == 0 ) # 0 means user does not exists
- {
- # the new user will create in UNIX DATABASE
- #
- # execute the Linux/Unix command in b/w ' '
- #
- `useradd $userName -d /home/$userName`; #useradd(create new user account -d(widout option))
- `chmod 700 /home/$userName`; # change the access permission of the files
- `chown -hR $userName /home/$userName`; # change ownership of user and group files
- `passwd $userName`; #modify/creat a user password in UNIX database
- `echo $mypass | smbpasswd -a $userName -s`;
- `echo $mypass | htpasswd -bcs /home/$userName/.htpasswd $userName -s`;
- print "\nEnter the Option --> : ";
- chomp ($option = <>);
- }
- #
- #it will run if user already exists!
- #
- else
- {
- print"\n User already exists! Try again .. \n\n";
- print "\nEnter the Option --> : ";
- chomp ($option = <>);
- }
- }
- #
- # Updating user option
- #
- elsif($option eq "u")
- {
- print "\n\n--- Updating User Menu --- \n\n";
- print "\nEnter the Option --> : ";
- chomp ($option = <>);
- }
- #
- # Deleting user option
- #
- elsif($option eq "d")
- {
- print "\n\n--- Deleting User Menu --- \n\n";
- print "\nEnter the Option --> : ";
- chomp ($option = <>);
- }
- #
- # Help Menu Option
- #
- elsif($option eq "h")
- {
- print "\n\n--- Help Menu --- \n\nExit program --> press q\n\nAdding user --> press a\n\nUpdating Password --> press u\n\nDelete user --> press d\n\n";
- print "\nEnter the Option --> : ";
- chomp ($option = <>);
- }
- #
- # If user press wrong option
- #
- else
- {
- print "\n\nYou select the wrong Option \n\nFor help press h \n\n";
- print "\nEnter your option --> : ";
- chomp ($option = <>);
- }
- }
- #
- # option q logic
- #
- until($option ne "q")
- {
- print "\nThe program is terminating. . . . . .\n\n";
- exit;
- }