Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Ldapsearch using variable will not work Post 302983824 by who10 on Monday 17th of October 2016 03:21:41 PM
Old 10-17-2016
Ldapsearch using variable will not work

When I execute the code below with cn set to the $adgroup variable, I get the following error:
Code:
Invalid DN syntax (34)
Additional information: 0000208F: NameErr: DSID-031001F7, problem 2006 (BAD_NAME), data 8349, best match of:
,ou=Resource,ou=groups,dc=abc,dc=somecompany,dc=com'

If I set cn equal to the group instead of using a variable, the code works perfectly fine.

What am I missing in regard to ldapsearch and variables that is causing this error?

Code:
#!/bin/bash
 #reads Groups.txt file and runs a new ldapsearch for group
while read -r adgroup; do
        echo $adgroup
        #ldapsearch connects to ldap, returns and formats member info, and writes to input.txt file
        ldapsearch -x -LLL -E pr=200/noprompt -o ldif-wrap=no -h abc-loc.somecompany.com \
        -D "account@somecompany.com" -w password -b "cn=$adgroup,ou=Resource,ou=groups,dc=abc,dc=somecompany,dc=com" \
         | grep member | sed 's/\\/\\\\/g' > /userid/bin/input.txt
         #reads input.txt file and runs a new ldapsearch for each member entry
        while IFS=":" read -r member info; do
                 #echo $info
                 ldapsearch -x -LLL -E pr=200/noprompt -h abc-loc.somecompany.com \
                -D "account@somecompany.com" -w password -b "ou=End Users,ou=Accounts,dc=abc,dc=somecompany,dc=com" \
                -s sub "distinguishedName=$info" displayName saMAccountName telephoneNumber mail department departmentNumber \
                extensionAttribute1 l st co userAccountControl |
                 #display output string in correct format
                awk -F: '
                NR == 1 {n = split (FLDS, T)
                        }
                        {OUT[$1] = substr ($2, 2)
                        }
                END     {for (i=1; i<=n; i++)   {printf "%s%s", ODL, OUT[T[i]]
                                 ODL = "|"
                                }
                         printf RS
                        }
                ' FLDS="displayName:sAMAccountName:telephoneNumber:mail:extensionAttribute1:department:departmentNumber:l:st:co:userAccountControl"
         #Define input filepath
        done < /userid/bin/input.txt
 #Define Group filepath
done < /userid/bin/GroupsTest1.txt


Last edited by rbatte1; 10-18-2016 at 06:07 AM.. Reason: Added CODE tags for output/errors
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

does this variable call work--Korn

I am new to the UNIX environment, but not to programming. My intention is to create a 2D array and print it. Since the Korn Shell does not support that kind of variable, the following is my solution right now. I have created a group of variables as follows: table00 table01 table02 table10... (2 Replies)
Discussion started by: morkfard
2 Replies

2. Red Hat

ldapsearch doesnt work.

Hii All, I am using openldap v2.3 on redhat El-4. When i run ldapsearch it returns all the entries. The command runs successfully. But when I run the ldapsearch with following filter option it doesnt work and immediately returns to the shell. ldapsearch uidNumber>=2000 I've started slapd... (0 Replies)
Discussion started by: shamik
0 Replies

3. Shell Programming and Scripting

Use variable in sed don't work.

Hi all. I have a script as below: cutmth=`TZ=CST+2160 date +%b` export cutmth echo $cutmth >> date.log sed -n "/$cutmth/$p" alert_sbdev1.log > alert_summ.log My purpose is to run through the alert_sbdev1.log and find the 1st occurence of 'Jan' and send everything after that line to... (4 Replies)
Discussion started by: ahSher
4 Replies

4. Shell Programming and Scripting

export variable from ksh script doesn't work

Hi there, in a script I have #!/usr/bin/ksh TEST=hello export TEST Problem is, that the variable doesn't get exported. I also tried typeset -x TEST=hello When I put the two lines in my .profile, the variable is set fine. Whats could be the problem here? (4 Replies)
Discussion started by: doc_symbiosis
4 Replies

5. UNIX for Dummies Questions & Answers

How does the PATH environmental variable work?

Hello. I have a question about how the PATH environment variable works. I wrote a script in $HOME/bin/gvim. I want it to be called instead of /usr/bin/gvim, so I've placed it before in the PATH. However, it is still the old one that is found. If I open an other terminal, I have the... (6 Replies)
Discussion started by: qwer
6 Replies

6. Shell Programming and Scripting

Exporting my dynamical variable won't work?

Even though the idea "might" not be great I still wrote this piece of code to get practice.. Which means that it is the CODE that matters here. Anyways; The intension is to create a program(or do we call it script?) that searches recursively through a folder to find a file - stored in a... (4 Replies)
Discussion started by: Pesk
4 Replies

7. Programming

LDAPSEARCH in C

Hi all, I've been searching for ldapsearch function these few days. Still I couldn't found the solution. I would like to translate this query ldapsearch -x -LLL -h new_IP -p new_Port -D "cn=jw" -w "dummy" -b "id=2311,o=WC,c=jp" -s sub to ldap_search_ext_s() function in C program. ... (0 Replies)
Discussion started by: tailangong
0 Replies

8. UNIX for Dummies Questions & Answers

Need assistance on using ldapsearch

Never knew of this command ldapsearch, but I would like to use it to lookup a single user and return where their office is. Is this possible? I'm totally starting from scratch. I already saw some of the gurus say read the man page, which is pretty greek when you don't know the details of... (1 Reply)
Discussion started by: srhadden
1 Replies

9. Shell Programming and Scripting

Work out max variable lengths in file

I have a pipe dilminted txt file with 30 variables in it. How can I calculate the maximum number of characters in each variable in the file. (2 Replies)
Discussion started by: RobWork
2 Replies

10. Shell Programming and Scripting

Grep doesn't work when assigning to variable

Hello, First of all, I'd like to say hello to all members of forum. Can You please help me with the matter described below? I am trying to fetch a data from the file to variable, I am doing this using below script: returned=`tail -50 SapLogs.log | grep -i -E "Error|"` echo $returned ... (2 Replies)
Discussion started by: jedzio
2 Replies
NEWGRP(1)                                                          User Commands                                                         NEWGRP(1)

NAME
newgrp - log in to a new group SYNOPSIS
newgrp [-] [group] DESCRIPTION
The newgrp command is used to change the current group ID during a login session. If the optional - flag is given, the user's environment will be reinitialized as though the user had logged in, otherwise the current environment, including current working directory, remains unchanged. newgrp changes the current real group ID to the named group, or to the default group listed in /etc/passwd if no group name is given. newgrp also tries to add the group to the user groupset. If not root, the user will be prompted for a password if she does not have a password (in /etc/shadow if this user has an entry in the shadowed password file, or in /etc/passwd otherwise) and the group does, or if the user is not listed as a member and the group has a password. The user will be denied access if the group password is empty and the user is not listed as a member. If there is an entry for this group in /etc/gshadow, then the list of members and the password of this group will be taken from this file, otherwise, the entry in /etc/group is considered. CONFIGURATION
The following configuration variables in /etc/login.defs change the behavior of this tool: SYSLOG_SG_ENAB (boolean) Enable "syslog" logging of sg activity. FILES
/etc/passwd User account information. /etc/shadow Secure user account information. /etc/group Group account information. /etc/gshadow Secure group account information. SEE ALSO
id(1), login(1), su(1), sg(1), gpasswd(1), group(5), gshadow(5). shadow-utils 4.5 01/25/2018 NEWGRP(1)
All times are GMT -4. The time now is 02:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy