LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices



Reply
 
Search this Thread
Old 12-26-2011, 10:16 PM   #1
vikki
Member
 
Registered: Jun 2009
Posts: 30

Rep: Reputation: 18
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:
 
Old 12-27-2011, 10:45 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950
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/
 
Old 12-28-2011, 08:38 AM   #3
vikki
Member
 
Registered: Jun 2009
Posts: 30

Original Poster
Rep: Reputation: 18
>> 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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How do I make an AWK script parse a Shell Variable Nerdio Linux - Newbie 4 11-16-2011 02:16 PM
[SOLVED] How to parse and modify these keywords using shell script? corone Programming 17 04-26-2011 08:33 AM
Python script parse NMEA data from GlobalSat BU-353 buffdigger Linux - Newbie 1 04-07-2010 08:29 PM
[shell script] execute command and parse output stoiss Programming 2 01-26-2009 02:49 AM
ssimple shell script to parse a file ~sed or awk stevie_velvet Programming 7 07-14-2006 04:41 AM


All times are GMT -5. The time now is 01:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration