LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   How can I configure a shell script which will parse ldap data in for each dn: (http://www.linuxquestions.org/questions/linux-server-73/how-can-i-configure-a-shell-script-which-will-parse-ldap-data-in-for-each-dn-920641/)

vikki 12-26-2011 10:16 PM

How can I configure a shell script which will parse ldap data in for each dn:
 
0 down vote favorite
share [fb] share [tw]


I have a LDIF database something like this.

Quote:

dn: uid=user1,ou=People,dc=example,dc=com
mail: user1@example.com
passwordexpirationtime: 20120113203000Z

dn: uid=user2,ou=People,dc=example,dc=com
mail: user2@example.com
passwordexpirationtime: 20120113203000Z

dn: uid=user3,ou=People,dc=example,dc=com
mail: user3@example.com
passwordexpirationtime: 20120113203000Z


How can I configure a shell script to parse each dn: check the value of passwordexpirationtime, compare it with current date. if less then 10 days then send a mail to value in mail attribute ?

If I search the value of attribute by grep passwordexpirationtime |awk -F ':' '{print $2}' It will return value for all dn: how will I know which mail: is associated by which dn:

David the H. 12-27-2011 10:45 AM

Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Do NOT use quote tags, as they don't preserve whitespace.


It's probably time for you to learn some of the advanced features of awk then. ;) I'm not going to do all your work for you, but if you redefine the RS (record separator) as '\n\n', it will process the input according to paragraphs, rather than lines. Then you can parse it for fields as usual (just remember that you have to count all the fields in the paragraph now).

It's also easy to test the values of fields, and print only the ones you want. In addition, gawk also has several time functions available:

http://www.gnu.org/software/gawk/man...Functions.html

It looks like you'll have to convert the final field into epoch-seconds before you can compare it to the current date (also in epoch seconds).

Here are a few useful awk references:
http://www.grymoire.com/Unix/Awk.html
http://www.gnu.org/software/gawk/man...ode/index.html
http://www.pement.org/awk/awk1line.txt
http://www.catonmat.net/blog/awk-one...ined-part-one/

vikki 12-28-2011 08:38 AM

>> Please use tags around your code and data, to preserve formatting and to improve readability. Do NOT use quote tags, as they don't preserve whitespace.

My Bad, Will take care in future, didnt knew the difference between the code & quote.

>> Please use tags around your code and data, to preserve formatting and to improve readability. Do NOT use quote tags, as they don't preserve whitespace.

I take that I need to learn now advanced bash. Thanks for the idea, Will work on it & update.


All times are GMT -5. The time now is 12:14 AM.