Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8631695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:15:12+00:00 2026-06-12T09:15:12+00:00

I am newbie to web programming and I have small shell script which basically

  • 0

I am newbie to web programming and I have small shell script which basically gives output with two results. It’s basically to find users on our directory.

#!/bin/bash
echo -n "Please enter username to lookup: "
read USERNAME
DISPLAYNAME=`ldapsearch -p xxx -LLL -x -w test -h abc.com -D abc -b dc=abc,dc=com sAMAccountName=$USERNAME | grep displayName`

if [ -z "$DISPLAYNAME" ]; then
  echo "No entry found for $USERNAME"
else 
  echo "Entry found for $USERNAME"
fi

Looking out for perl web code which can display the results on browser.

I know, I would be asking too much here, but I would really appreciate if anyone can give me right direction to achieve this.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:15:12+00:00Added an answer on June 12, 2026 at 9:15 am

    First of all, do not use $USERNAME in your BASH script. $USERNAME is a BASH variable that contains the current user’s name. In fact, it is generally a bad idea to use UPPERCASE variables in BASH. Most BASH environment variables are upper case and that can lead to confusion. It is good practice to have your variables lower case.

    Also, since I imagine you want to do this using an HTML form, you cannot have BASH read from STDIN. Modify tour script to take the user name as an argument:

    BASH:

    #!/bin/bash
    user=$1;
    DISPLAYNAME=`ldapsearch -p xxx -LLL -x -w test -h abc.com -D abc -b dc=abc,dc=com sAMAccountName=$user | grep displayName`
    if [ -z "$DISPLAYNAME" ]; then
      echo "No entry found for $user"
    else 
      echo "Entry found for $user"
    fi
    

    Perl:

    #!/usr/bin/perl
    use CGI qw(:standard);
    use CGI::Carp qw(warningsToBrowser fatalsToBrowser); 
    use strict;
    use warnings;
    ## Create a new CGI object
    my $cgi = new CGI;
    ## Collect the value of 'user_name' submitted by the webpage
    my $name=$cgi->param('user_name');
    
    ## Run a system command, your display_name.sh,
    ## and save the result in $result
    my $result=`./display_name.sh $name`;
    
    ## Print the HTML header
    print header;
    ## Print the result
    print "$result<BR>";
    

    HTML:

    <html>
    <body>
    <form ACTION="./cgi-bin/display_name.pl" METHOD="post">
    <INPUT TYPE="submit" VALUE="Submit"></a>
    <INPUT TYPE="text" NAME="user_name"></a>
    </form>
    </body>
    </html>
    

    This should do what you need. It assumes that both scripts are in the ./cgi-bin/ directory of your webpage and are called display_name.sh and display_name.pl. It also assumes that you have set their permissions correctly (they need to be executable by apache2’s user, www-data). Finally, it assumes that you have set up apache2 to allow execution of scripts in ./cgi-bin.

    Is there a specific reason you want to use BASH? You could just do everything directly from the Perl script:

    #!/usr/bin/perl
    use CGI qw(:standard);
    use CGI::Carp qw(warningsToBrowser fatalsToBrowser); 
    use strict;
    use warnings;
    ## Create a new CGI object
    my $cgi = new CGI;
    ## Collect the value of 'name' submitted by the webpage
    my $name=$cgi->param('user_name');
    
    ## Run the ldapsearch system command
    ## and save the result in $result
    my $result=`ldapsearch -p xxx -LLL -x -w test -h abc.com -D abc -b dc=abc,dc=com sAMAccountName=$name | grep displayName`;
    
    ## Print the HTML header
    print header;
    ## Print the result
    $result ? 
          print "Entry found for $name<BR>" : 
          print "No entry found for $name<BR>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a newbie in web services. I have a JAX-WS service which I
I am a newbie at web programming. I have basic PHP programming skills. From
I’m a newbie to web programming and trying to write a simple app, which
Pardon the dumb newbie question here; web programming isn't my forte... (blush) I have
dear all.i newbie at web programming and until now i still have learn about
i am a newbie on web development, so i have some problems first of
I am a newbie when it comes to Ruby On Rails (and web programming
I've read about phonegap which enables users to write web-based apps for android and
i'm newbie at web developing. i have some input form.i'm using jquery 1.4.2 inside
I'm newbie to BSD socket programming in C. I can query a web address

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.