473,698 Members | 2,102 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 2308
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
2163
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
1996
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
1988
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
2371
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
3609
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
3517
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
3269
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
54514
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
2349
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
9014
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...
1
8885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8855
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7708
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
6515
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...
0
4358
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2320
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1995
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.