Script to check if user can bind, then output to file

Hi,

I've been trying to find the answer with no luck. I'm hoping someone can help me. Here's what I need to do:

Run a KSH script that will check:

  1. Server (Client) Type (AIX 5.3, 6.1, SUSE, and HP-UX are the possibilities).
  2. LDAP.cfg is configured correctly and the ldap client service is running. The way to tell is to see if a user with an account on the LDAP directory can bind from the Server (Client) side. If so, then output to yes.xml.....if no, then output to no.xml. Either way the server name and OS type need to be in the file, separated by commas.

That's it! know the AIX command to check ldap is lsldap -a passwd (ldap_user_id). That's all I know as far as what to do here. I don't need any ldap commands for the other OS types, they are simimar and I can handle that. I just don't know how to collect, validate and output info in a script. Can anyone help me with this?

Thanks in advance,

D

Use the ldap client command to bind as a user. If the command fails, you should
get nonzero exit code. If it succeeds, you should get
a zero exit code. If you can confirm this, you just
put the command in an if statement:

1 Like

It's simple enough!!

Hope you get the idea from here:

#!/usr/bin/ksh

lsldap -a passwd testuser
ret=$?

if [ $ret -ne 0 ]; then
    echo `uname -n`","`uname -o` >>/tmp/no.xml
else
    echo `uname -n`","`uname -o` >>/tmp/yes.xml
fi
1 Like

Thanks for your responses, I'm going to test them now and get back to you.... : )

---------- Post updated at 04:26 PM ---------- Previous update was at 03:34 PM ----------

Hi admin_xor,

I got this error:

uname: Not a recognized flag: o
Usage: uname [-snlrvmaxupfFMS:T:L]

Looks like the uname -o after the commas isn't a valid flag, there are others...can you tell me which to try next? There are more than I want to try using trial and error unless I have to....don't want unexpected results to cause issues in the environment if I can help it.

Thanks,

D

---------- Post updated at 04:38 PM ---------- Previous update was at 04:26 PM ----------

I think I will try the -r flag....brb

---------- Post updated at 04:53 PM ---------- Previous update was at 04:38 PM ----------

Hi all,

I just used the"-x" flag to gather all the system info and dump into the file. It works beautifully, thank you all so much!!

Cheers,

D