Wednesday, March 8, 2017

ldapsearch and awk follies

 #!/bin/bash  
ldapsearch -x -D "CN=serviceacct,OU=here" -w n0tagain\!\!\! -h 6.6.6.6 -p 3268 
  -LLL "(&(objectCategory=person)(objectclass=user)(memberOf=CN=slack-here,OU=here))" 
   mail departmentNumber | awk '!/CN=/{print $2}' > yes ; awk 'NF > 0' yes > no ; 
   awk 'NR%2{printf "%s,",$0;next;}1' no > yes ; 
   mv yes output-here.`date +"%y%m%d"` ; rm -f no ;  
ldapsearch -x -D "CN=serviceacct,OU=there" -w alw4ys\@d0h\! -h 9.9.9.9 -p 3268 
   -LLL "(&(objectCategory=person)(objectclass=user)(memberOf=CN=slack-there,OU=there))" 
   mail description | awk '!/CN=/{print $2}' > yes ; awk 'NF > 0' yes > no ; 
   awk 'NR%2{printf "%s,",$0;next;}1' no > yes ; 
   awk -F, '{print $2,$1}' OFS=, yes > maybe ; 
   mv maybe output-there.`date +"%y%m%d"` ; rm -f no ; rm -f yes  
cat output-here.`date +"%y%m%d"` output-there.`date +"%y%m%d"` >> output-all.`date +"%y%m%d"` ;  
mailx -s "service users output.`date +"%y%m%d"`" me.in@hell <output-all.`date +"%y%m%d"` ;  
rm -f output-*  
Post a Comment