{"id":54,"date":"2008-01-14T15:15:38","date_gmt":"2008-01-14T07:15:38","guid":{"rendered":"http:\/\/www.sysadmindayph.com\/blog\/perl-one-liner-search-and-replace\/"},"modified":"2008-01-14T15:16:26","modified_gmt":"2008-01-14T07:16:26","slug":"perl-one-liner-search-and-replace","status":"publish","type":"post","link":"https:\/\/www.sysadmindayph.com\/blog\/perl-one-liner-search-and-replace\/","title":{"rendered":"Perl One Liner: Search and Replace for LDAP ldif file"},"content":{"rendered":"<p>Quick post&#8230; note to self&#8230;<\/p>\n<p>In resetting passwords for one of our customers, we have to create the necessary <strong>LDIF <\/strong>file (yep, system uses <strong>LDAP<\/strong>), and do the <strong>ldapmodify <\/strong>command.<\/p>\n<p>Instead of creating ldif file (or editing existing) every time there is a password reset,  why &#8216;vi&#8217; every time when you can do a one line perl command to replace the &#8216;uid&#8217; part of the <strong>LDIF file<\/strong>?<\/p>\n<p>Example:<\/p>\n<p>After checking that the password was indeed locked, we create an LDIF file like this one:<\/p>\n<blockquote><p> # more  \/tmp\/ldif.txt<br \/>\ndn: uid=guttekg,ou=people,dc=domain,dc=domain2,dc=domain3,dc=com<br \/>\nchangetype: modify<br \/>\nreplace: userPassword<br \/>\nuserPassword: R3s#tn9<\/p><\/blockquote>\n<p>and execute the ldapmodify command:<\/p>\n<blockquote><p> ldapmodify -D &#8220;cn=Directory Manager&#8221; -h ldap_server -f \/tmp\/ldif.txt<\/p><\/blockquote>\n<p>For the next password reset, we don&#8217;t have to do &#8216;vi&#8217; and edit the ldif file. Simpley do:<\/p>\n<blockquote><p>perl -p -i -e &#8216;s\/oldstring\/newstring\/g&#8217; *<\/p><\/blockquote>\n<p>.. and we&#8217;re done.. (after the ldapmodify of course)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quick post&#8230; note to self&#8230; In resetting passwords for one of our customers, we have to create the necessary LDIF file (yep, system uses LDAP), and do the ldapmodify command. Instead of creating ldif file &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-54","post","type-post","status-publish","format-standard","hentry","category-tips"],"_links":{"self":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/54","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/comments?post=54"}],"version-history":[{"count":0,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/54\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/media?parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/categories?post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/tags?post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}