1

As i am new to python and ldap, please hep me convert the below shell code into python(version 2.6.6).

can some pls explain what this below shell code does and what is the use of -b option here

Shell code :

ldapsearch -x -h ldap.bbc.network.lcl -p 3477 -b "DC=bbc,DC=network,DC=lcl" -D "CN=LDAP\, Mine,OU=Resource Accounts,OU=Enterprise,DC=bbc,DC=network,DC=lcl" -w f2oH@LQ^911 "center=1234"
Bellerofont
  • 1,081
  • 18
  • 17
  • 16
Learner
  • 31
  • 9
  • If you just want to run that command, do it with Bash. Using Python for that won't give any benefit. Or do you want to write a Python version of that command? BTW, Python 2.6.6 is rather ancient. You should seriously consider learning Python 3, Python 2 will reach its official End Of Life in 2020. – PM 2Ring May 27 '18 at 11:44
  • Actually , i need to do this functionality in python .Thatswhy. But i am new to both shell and python – Learner May 27 '18 at 11:47
  • 2
    Of course you could write a Python script that just runs a shell command, but one of Pythons' strengths is the vast selection of libraries. Have a look at https://www.python-ldap.org – simonz May 27 '18 at 12:30
  • The shell code will never have an End Of Life and learning one thing is easier than two. I'd focus on polishing what already works rather than rewriting it to get back to where you already are. Plus shell programmers don't worry about PEP compliance which makes it easier to avoid a few neuroses. – chicks May 27 '18 at 13:29
  • Pls, someone say "what is the username from the shell code " – Learner Jun 07 '18 at 10:08

1 Answers1

1

To find out what each option does, take a look at the man page of command, here.

As stated there:

-b searchbase Use searchbase as the starting point for the search instead of the default.

To run the command via python interpreter you can use structures like this:

For more info visit this Q/A.

Saleh
  • 1,819
  • 1
  • 17
  • 44