Quote:
Originally Posted by pan64
would be nice to see the original source file.
|
Pan64,
Here is the script:
#!/bin/bash
#################################################################################################### #############
# #
# This script will pull the most recent wbinfo for the rdusers group for chef to deploy to all servers. #
# #
# Created by Lee Higginbotham #
# Created on 09NOV14 #
# All rights reserved by #
# #
# This script will also generate a log file named new_user_for_chef.log' #
# This script is to be run by root #
# #
#################################################################################################### #############
# #
#################################################################################################### #############
# #
# Changing directory to the working directory. #
# #
#################################################################################################### #############
# #
echo "Changing the directory to /opt/chef/bin/users_group." >> /var/log/new_user_for_chef.log
echo $PWD >> /var/log/new_user_for_chef.log
cd /opt/chef/bin/users_group
# #
#################################################################################################### #############
# #
# Backing up the previous users.txt file for comparison and removing the diff.txt and diff_clean.txt #
# #
#################################################################################################### #############
# #
echo "------------------------------------------------------------------------------------------------" >> /var/log/new_user_for_chef.log
echo "-----------------------------------NEW USERS RUN--------------------------------------------" >> /var/log/new_user_for_chef.log
echo "------------------------------------------------------------------------------------------------" >> /var/log/new_user_for_chef.log
echo "Copying the old file to users_old.txt." >> /var/log/new_user_for_chef.log
ls -al users* >> /var/log/new_user_for_chef.log
cp users.txt users_old.txt
echo "Removing the diff.txt and diff_clean.txt and touching them to create a clean environment" >> /var/log/new_user_for_chef.log
rm -rf diff.txt
rm -rf diff_clean.txt
ls -al >> /var/log/new_user_for_chef.log
touch diff.txt
touch diff_clean.txt
ls -al >> /var/log/new_user_for_chef.log
# #
#################################################################################################### #############
# #
# Pulling in the new AD group memebership info. #
# #
#################################################################################################### #############
# #
echo "Querying AD for the updated domain rdusers group members and saving it to users.txt." >> /var/log/new_user_for_chef.log
wbinfo --group-info "Employees" | cut -d ':' --complement -f -3 | iconv -f utf-8 -t ascii//translit > /opt/chef/bin/users_group/users.txt
# #
#################################################################################################### #############
# #
# Performing the comparison of the files. #
# #
#################################################################################################### #############
# #
echo "Performing the comparison of the files." >> /var/log/new_user_for_chef.log
dwdiff -Pl -3 users.txt users_old.txt > diff.txt
echo "Here is the result of the comparison:" >> /var/log/new_user_for_chef.log
cat diff.txt >> /var/log/new_user_for_chef.log
# #
#################################################################################################### #############
# #
# Cleaning the file. #
# First I'm going to remove the two lines that contain a double equal signs lines. #
# Secondly, I'm going to remove the leading #
# and trailing commas to get the new user name #
# #
#################################################################################################### #############
# #
#iconv -f utf-8 -t ascii//translit users.txt
sed -i -e "/=/d" diff.txt
sed 's/\,/\n/g' diff.txt | sed 's/\_//g' > diff_clean.txt
#sed 's/\,/\n/g' diff.txt > diff_clean.txt
# #
#################################################################################################### #############
# #
# Here is the file after removing the commas to provide a list of new domain users. #
# #
#################################################################################################### #############
# #
cat diff_clean.txt >> /var/log/new_user_for_chef.log
echo "The new user import is ready to run in Chef." >> /var/log/new_user_for_chef.log
echo "------------------------------------------------------------------------------------------------" >> /var/log/new_user_for_chef.log
echo "-----------------------------------END USERS RUN--------------------------------------------" >> /var/log/new_user_for_chef.log
echo "------------------------------------------------------------------------------------------------" >> /var/log/new_user_for_chef.log
Sincerely,
Lee