473,385 Members | 1,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Can any one help me please

2
I wrote the program and its not giving me correct answer can any one help me with that please and specify my mistake please it will be highly appreciable...
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
  1. #!/usr/bin/perl -w
  2.  
  3. #use Getopt::Std;
  4.  
  5. print "\nWelcome to the New Era!! Assignment 1!! \n\nFor help to run program press h !!\n\n ";
  6.  
  7. #
  8. # Take input from user
  9. #
  10. print "\nEnter the Option --> : ";
  11. chomp ($option = <>);
  12.  
  13. while($option ne "q")
  14. {
  15. #
  16. # Adding user option
  17. #
  18.   if($option eq "a")
  19.   {
  20.     print "\n\n--- Add User Menu --- \n\n";
  21.     print "\nEnter User Name --> : ";
  22.     chomp ($userName = <>);
  23. #
  24. #Checking for the user if its exist in the UNIX
  25. #
  26.     $chkrs = 'grep -c -w $username /etc/passwd'; # grep : search files for lines, match given pattern
  27. print "\n User $chkrs \n";
  28.     if($chkrs == 0 )  # 0 means user does not exists
  29.     {
  30.     # the new user will create in UNIX DATABASE
  31. #
  32. #  execute the Linux/Unix command in b/w ' '
  33. #
  34.     `useradd $userName -d /home/$userName`; #useradd(create new user account -d(widout option))
  35.     `chmod 700 /home/$userName`; # change the access permission of the files
  36.     `chown -hR $userName /home/$userName`; # change ownership of user and group files
  37.     `passwd $userName`; #modify/creat a user password in UNIX database
  38.     `echo $mypass | smbpasswd -a $userName -s`;
  39.     `echo $mypass | htpasswd -bcs /home/$userName/.htpasswd $userName -s`;
  40.          print "\nEnter the Option --> : ";
  41.          chomp ($option = <>);
  42.     }
  43. #
  44. #it will run if user already exists!
  45. #
  46.     else
  47.     {
  48.     print"\n User already exists! Try again .. \n\n";
  49.         print "\nEnter the Option --> : ";
  50.         chomp ($option = <>);
  51.     }
  52.  
  53.   }
  54. #
  55. # Updating user option
  56. #
  57.   elsif($option eq "u")
  58.   {
  59.     print "\n\n--- Updating User Menu --- \n\n";
  60.     print "\nEnter the Option --> : ";
  61.     chomp ($option = <>);
  62.   }
  63. #
  64. # Deleting user option
  65. #
  66.   elsif($option eq "d")
  67.   {
  68.     print "\n\n--- Deleting User Menu --- \n\n";
  69.     print "\nEnter the Option --> : ";
  70.     chomp ($option = <>);
  71.   }
  72. #
  73. # Help Menu Option
  74. #
  75.   elsif($option eq "h")
  76.   {
  77.     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";
  78.     print "\nEnter the Option --> : ";
  79.     chomp ($option = <>);
  80.   }
  81. #
  82. # If user press wrong option
  83. #
  84.   else 
  85.   {
  86.     print "\n\nYou select the wrong Option \n\nFor help press h \n\n";
  87.     print "\nEnter your option --> : ";
  88.     chomp ($option = <>);
  89.   }
  90.  
  91. }
  92.  
  93. #
  94. # option q logic
  95. #
  96. until($option ne "q")
  97. {
  98.   print "\nThe program is terminating. . . . . .\n\n";
  99.   exit;
  100. }
Mar 23 '08 #1
5 2266
KevinADC
4,059 Expert 2GB
Your code is a perfect example of why you should use the "strict" pragma:

use strict;

chomp ($userName = <>);
Checking for the user if its exist in the UNIX
$chkrs = 'grep -c -w $username /etc/passwd';

See the problem? "strict" would have caught that typo right away.
Mar 24 '08 #2
tabani
2
thanks mate..

i change it...
but it does not work

can you please tell me about htpasswd coz its not running at my side

regards
Mar 24 '08 #3
nithinpes
410 Expert 256MB
thanks mate..

i change it...
but it does not work

can you please tell me about htpasswd coz its not running at my side

regards
You have used single quotes for passing command to terminal in this line of your initial script:
Expand|Select|Wrap|Line Numbers
  1. $chkrs = 'grep -c -w $username /etc/passwd';
  2.  
Change that to reverse quotes:
Expand|Select|Wrap|Line Numbers
  1. $chkrs = `grep -c -w $username /etc/passwd`;
  2.  
You have used reverse quotes properly for passing commands in remaining part of your script. Have you rectified this and tried?
Mar 24 '08 #4
KevinADC
4,059 Expert 2GB
You have used single quotes for passing command to terminal in this line of your initial script:
Expand|Select|Wrap|Line Numbers
  1. $chkrs = 'grep -c -w $username /etc/passwd';
  2.  
Change that to reverse quotes:
Expand|Select|Wrap|Line Numbers
  1. $chkrs = `grep -c -w $username /etc/passwd`;
  2.  
You have used reverse quotes properly for passing commands in remaining part of your script. Have you rectified this and tried?

Good catch, I entirely missed the single-quotes problem.
Mar 24 '08 #5
KevinADC
4,059 Expert 2GB
thanks mate..

i change it...
but it does not work

can you please tell me about htpasswd coz its not running at my side

regards

You need to ask questions that can be answered. You may as well ask:

Can you please tell me about automobiles coz mine is not running.

How can you answer a question like that?
Mar 24 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Numberwhun | last post by:
Hello everyone! I am trying to learn java and have run into kind of a snag. Here is the code that I have so far: ------ <begin_code> ---------- import javax.swing.*; import...
1
by: HolaGoogle | last post by:
Hi all, Please help me with the following..it's realy urgent and i tried everything i could and i can't get it work properly!! Thanks in advance. Here's what i'm trying to accomplish: in my...
0
by: s_erez | last post by:
Hi, This is a realy tricky one. I have an ASP.NET application where some pages are reading data from a DB and presenting reports. In order for the user to wait while the page is reading data from...
2
by: rked | last post by:
I get nameSPAN1 is undefined when I place cursor in comments box.. <%@ LANGUAGE="VBScript" %> <% DIM ipAddress ipAddress=Request.Servervariables("REMOTE_HOST") %> <html> <head> <meta...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
4
by: pshindle | last post by:
DB2 Team - I just downloaded and unzipped the new Fixpack 9 for DB2 ESE V8 for Windows (FP9_WR21350_ESE.exe). I then burned the unzipped Fixpack files to a CD. I proceded to install this...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
1
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and...
4
by: fatboySudsy | last post by:
Hi, I have constructed a client program that has given me some error codes that i just cannot see. I was wondering if a different set of eyes with much more experience than me could help me out. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.