LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-22-2013, 10:45 AM   #1
byran cheung
Member
 
Registered: Sep 2013
Posts: 321

Rep: Reputation: Disabled
check record


I would like to write a shell script to do the following , would advise how to make it ? very thanks

1. Connect LDAP server ( Id : user , password : pass )
2. check the field "user_account_create_date" in the LDAP server , the format of data in this field in LDAP is ABC20130922 ( 22 Sep , 2013) , find the record in this field to check last 8 digits , if the date is within 7 days ( that mean the account is created within 7 days ), then do ...

could advise what to make this script ?

thanks

Last edited by byran cheung; 09-22-2013 at 07:04 PM.
 
Old 09-22-2013, 11:31 PM   #2
sxa
Senior Member
 
Registered: Aug 2003
Location: Austin, TX
Distribution: Mac OS 10.7 / CentOS 6(servers) / xubuntu 13.04
Posts: 1,186

Rep: Reputation: 49
Hello Bryan,

If you are new to bash scripting, a great place to start is the bash guide for beginners found at http://www.tldp.org/LDP/Bash-Beginne...ers-Guide.html

As for the specific script that you want, the following is an LDAP Query Script that might give you the baseline for accomplishing what you need http://daverdave.com/node/9
 
Old 09-22-2013, 11:41 PM   #3
byran cheung
Member
 
Registered: Sep 2013
Posts: 321

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sxa View Post
Hello Bryan,

If you are new to bash scripting, a great place to start is the bash guide for beginners found at http://www.tldp.org/LDP/Bash-Beginne...ers-Guide.html

As for the specific script that you want, the following is an LDAP Query Script that might give you the baseline for accomplishing what you need http://daverdave.com/node/9
Hi sxa ,

I am new to shell writing , would you please advise a simple sample ? thanks
 
Old 09-23-2013, 12:38 AM   #4
sxa
Senior Member
 
Registered: Aug 2003
Location: Austin, TX
Distribution: Mac OS 10.7 / CentOS 6(servers) / xubuntu 13.04
Posts: 1,186

Rep: Reputation: 49
Below is a sample bash script using ldapsearch, I don't have access to an LDAP server at the moment to test the ldapsearch command, but this will find all users that were created since the timestamp. Using the date command we look for the time stamp exactly 7 days from your current system date.

Again, you will need to modify the ldapsearch command with your proper IP and credentials for your LDAP server but this will output the users that have been created since the timestamp to the specified.

You said you want to do an action against these users, you would want to start by researching the various ways to read files in bash. You don't specify what action you want to do take, and the best approach will vary based on that action, but I hope this and the links provided will give you a starting point.

Code:
#!/bin/bash

timestamp = `date --date="-7 days" +%Y%m%d%k%m%S`Z

ldapsearch -h 192.168.1.100 -p 389 -D cn=admin,o=services -w pass -x
"(&(objectclass=*)(createTimestamp>=$timestamp))" + > /tmp/users.txt
 
Old 09-23-2013, 04:30 AM   #5
byran cheung
Member
 
Registered: Sep 2013
Posts: 321

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sxa View Post
Below is a sample bash script using ldapsearch, I don't have access to an LDAP server at the moment to test the ldapsearch command, but this will find all users that were created since the timestamp. Using the date command we look for the time stamp exactly 7 days from your current system date.

Again, you will need to modify the ldapsearch command with your proper IP and credentials for your LDAP server but this will output the users that have been created since the timestamp to the specified.

You said you want to do an action against these users, you would want to start by researching the various ways to read files in bash. You don't specify what action you want to do take, and the best approach will vary based on that action, but I hope this and the links provided will give you a starting point.

Code:
#!/bin/bash

timestamp = `date --date="-7 days" +%Y%m%d%k%m%S`Z

ldapsearch -h 192.168.1.100 -p 389 -D cn=admin,o=services -w pass -x
"(&(objectclass=*)(createTimestamp>=$timestamp))" + > /tmp/users.txt
thx reply ,

could advise if I would like to check the date string ( as the above question ) , what can I do ? thanks
 
Old 09-25-2013, 01:09 AM   #6
byran cheung
Member
 
Registered: Sep 2013
Posts: 321

Original Poster
Rep: Reputation: Disabled
About the above requirement 2 " check the field "user_account_create_date" in the LDAP server , the format of data in this field in LDAP is ABC20130922 ( 22 Sep , 2013) , find the record in this field to check last 8 digits , if the date is within 7 days ( that mean the account is created within 7 days ), then do ..." ,

how to write this part of script ? anyone can advise , thanks
 
  


Reply



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
Postfix does not check for MX record for multilevel subdomains lukess Linux - Server 2 10-06-2011 09:16 AM
how to make resolver ask for A record before AAAA record Skaperen Linux - Networking 25 03-02-2010 06:36 PM
DDNS record and a static PTR record mou5e Linux - Networking 2 01-22-2008 01:16 AM
Unable to record mic-in with SoundBlaster Live! while able to record other sources max76230 Linux - Newbie 2 03-14-2005 04:31 AM
Boot disk; check. CD in drive; check. Doesn't work; check. Hal DamnSmallLinux 7 02-04-2004 02:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:33 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
Open Source Consulting | Domain Registration