Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Command reference.
- #/opt/splunk-cluster/splunk/bin/splunk cmd python ./migrate-users.py --username admin --password passwd /tmp/migration/users/
- #global variables
- #List of users
- USER_LIST=`ls -1 /mnt/pool2/search_head_pool/etc/users`
- #Users home dirs
- source="/mnt/pool2/search_head_pool/etc/users"
- #splunk admin password so script can run
- admin_password="admin_password_here"
- #dirs to store a copy of users dirs before migration
- base_dir="/mnt/backup/cluster-work/migration"
- in_progress="${base_dir}/inprogress"
- skipped="${base_dir}/skipped"
- complete="${base_dir}/complete"
- logs="${base_dir}/logs"
- ######
- #MAIN#
- ######
- do_staged_only="0"
- #skip ldap check and dir inprogress creation.
- if [ $do_staged_only = 0 ]; then
- #Check account in ldap. If it exists then copy files to staging.
- count=0
- for user in $USER_LIST
- do
- found=` ldapsearch -h 10.1.1.1 -E pr=10000/noprompt -D "CN=ldaplookupaccount" -w ldappassword -b "OU=People,OU=eProfile,DC=core,DC=dir,DC=splunk,DC=com" -L -x "CN=$user" | grep memberOf | grep Splunk | sort -u | wc -l`
- if [ $found = 0 ]; then
- echo "$count: $user $found. Skipping user"
- cp -rp ${source}/$user ${skipped}
- else
- echo "Staging ${user}"
- mkdir ${in_progress}/${user}
- cp -rp ${source}/${user} ${in_progress}/${user}
- fi
- ((count++))
- done
- echo "doing ldap"
- fi
- #Process all files in staging area and try splunk import script against specific user dir (dir has a double dir name so we can call the script once per user dir).
- staged_users=`ls -1 ${in_progress}`
- for staged in $staged_users
- do
- mig_status=$( { /opt/splunk-cluster/splunk/bin/splunk cmd python ./migrate-users.py --username admin --password ${admin_password} $in_progress/$staged > $logs/$staged.log; } 2>&1 )
- stanza_found=`cat $logs/$staged.log | grep -c Found`
- stanza_wrote=`cat $logs/$staged.log | grep -c Wrote`
- date=`/bin/date`
- if [[ $mig_status == *"User does not exist"* ]]
- then
- echo "$date,username=$staged,status=fail,message=User_does_not_existi,log_file=$logs/missing_user/${staged}.log"
- mv $logs/$staged.log $logs/missing_user/${staged}.log
- else
- echo "$date,username=$staged,status=success,Found=$stanza_found,wrote=$stanza_wrote,log_file=$logs/$staged.log"
- fi
- if [ $stanza_wrote != 0 ]; then
- echo "move to complete $in_progress/$staged"
- echo "$staged .$stanza_wrote."
- #mv -v $in_progress/$staged $complete
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement