#!/usr/bin/perl
%h=(
"/etc/samba/smb.conf"=>
{
"search_string_1"=>"replace_string_1",
"search_string_2"=>"replace_string_2",
},
"/etc/openldap/ldap.conf"=>
{
"search_string_3"=>"replace_string_3",
"search_string_4"=>"replace_string_4",
},
"/path/to/next/file"=>
{
"search_string_5"=>"replace_string_5",
"search_string_6"=>"replace_string_6",
},
);
for $i (keys %h){
local $/;
open I, "$i";
$_=<I>;
for $j (keys %{$h{$i}}){
s/$j/$h{$i}{$j}/g
}
close I;
open I, ">$i";
print I $_;
close I;
}
Before running this code do a backup of those files. Add red sections of code with search and replace strings for all the files that you need.
for F-NAME in /etc/samba/smb.conf /etc/openldap/ldap.conf /etc/openldap/slapd.conf /etc/smbldap-tools/smbldap_bind.conf /etc/smbldap-tools/smbldap.conf ; do
# make new version ( keep source safe )
cp -f /backup/$F-NAME $F-NAME
case $F-NAME in
/etc/samba/smb.conf)
# should replace all occurences of ou=Computer by ou=Computer_id
cat $F-NAME | sed 's/"ou=Computer"/"ou=Computer_id"/g'
# should replace all occurences of ou=User by ou=User_id
cat $F-NAME | sed 's/"ou=User"/"ou=User_id"/g'
exit
;;
/etc/openldap/ldap.conf)
cat $F-NAME | sed 's/"rootpwd manager"/"rootpwd director"/g'
exit
;;
..............
..............
..............
esac
done ;
---------- Post updated at 11:21 PM ---------- Previous update was at 12:44 PM ----------