473,756 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can any one help me please

2 New Member
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 2315
KevinADC
4,059 Recognized Expert Specialist
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 New Member
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 Recognized Expert Contributor
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 Recognized Expert Specialist
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 Recognized Expert Specialist
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
2168
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 javax.swing.JApplet; import javax.swing.JOptionPane; import java.awt.Graphics;
1
2004
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 form i have a table with 3 rows (3 input text), in which user can enter values and then clik save. When he clicks the Save button, i'd like to be able to add the created items to the end of my table
0
1996
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 the DB I am using a DIV with a please wait message which is removed once the page is loaded. In addition I am using a global error handling using the Application_Error void in the Global.asax file. when the application is loading a page which...
2
2378
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 http-equiv="Content-Type" content="text/html;
7
3615
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> </head> <style type="text/css">
4
3521
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 Fixpack on a test machine running ESE but encountered a serious error during the install. It started 'copying new files' but then stopped cold and displayed a dialog box asking me to "Please insert disk 1". (It all fit on one CD!) I clicked OK...
23
3282
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 to create certain textboxes, labels, and combo boxes? Any ideas would be appreciated. Thanks
1
54529
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 we instruct our experts to ignore any such PMs completely Be sure to give the version of Access that you are working with and the Platform and OS if applicable.
4
2357
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. Here are the error codes and underneath i have listed the program. Thanks in advance for looking. client.c: In function `main': client.c:118: error: syntax error before '-' token client.c: At top level: client.c:132: error: conflicting types...
0
9455
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9271
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10031
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9869
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7242
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3354
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2665
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.