Skip to content
Snippets Groups Projects

Add script to move between groups

Merged Bo-Chun Chen requested to merge louistw/rabbitmq_agents:feat-migration-script into main
user_migrate.sh 100644 → 100755
+ 13
7
#!/bin/bash
group_options=(gpfs4 gpfs5)
gpfs4_home="/gpfs4/data/user/home"
gpfs5_home="/gpfs5/data/user/home"
user=$1
group_to=$2
if [[ -z "${group_to}" ]]; then
echo "Usage: $0 USER TARGET_GROUP"
exit 1
elif [[ "${group_to}" != "gpfs4" && "${group_to}" != "gpfs5" ]]; then
echo "Target group should be \"gpfs4\" or \"gpfs5\", got \"${group_to}\"."
elif [[ ! " ${group_options[*]} " =~ [[:space:]]${group_to}[[:space:]] ]]; then
echo "Invalid target group"
echo "Available options: ${group_options[*]}, got ${group_to}"
exit 1
fi
getent passwd "$user" > /dev/null 2&>1
if [[ $? -ne 0 ]]; then
if ! getent passwd "$user" > /dev/null 2>&1; then
echo "The user $user does not exist"
exit 1
fi
@@ -21,17 +24,20 @@ fi
cd /cm/shared/rabbitmq_agents || exit
source venv/bin/activate
if [[ "$group_to" == "gpfs4" ]]; then
group_from=gpfs5
dir_from="$gpfs5_home/$user/"
dir_to="$gpfs4_home/$user"
else
group_from=gpfs4
dir_from="$gpfs4_home/$user/"
dir_to="$gpfs5_home/$user"
fi
if [[ -d "/$group_from/data/user/home/$user" ]]; then
./account_manager.py "$user" hold
rsync -a --delete "/$group_from/data/user/home/$user/" "/$group_to/data/user/home/$user"
rsync -a --delete "$dir_from" "$dir_to"
./group_manager.py "$user" -g "$group_to"
./group_manager.py "$user" -d -g "$group_from"
Loading