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!
First of all, do not use
$USERNAMEin your BASH script.$USERNAMEis 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:
Perl:
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: