473,545 Members | 1,351 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 2294
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
2153
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
1974
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...
0
1972
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...
2
2348
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
3578
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
3505
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...
23
3241
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
54472
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...
4
2326
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:...
0
7467
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...
0
7401
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...
0
5971
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...
1
5326
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...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1879
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
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
703
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...

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.