atom-community / atom-community/atom-script
change UID and GID for all users in multiple servers
- Dominant language
- JavaScript
- Stars
- 730
- Forks
- 264
- PR merge metrics
- No merged PRs in 30d
Description
I want to automate the script for no user interaction. so far with the script below, I can manually login to each server and run the script to change UID and ownership of files of the user. I have a similar script for GID. all the users are managed locally no ldap.
#!/bin/bash
if [ "$#" -ne 3 ]; then
echo "Changing the UID of a User and modify ownership of his files and directories."
echo "Usage: changeUID.sh [username] [oldUID] [newUID]" >&2
exit 1
fi
read -p "Changing the UID of user '$1' from $2 to $3. Proceed (y/n)? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
# check user
USEREXISTS=$(cat /etc/passwd | grep -e "$1:[^:]*:$2" | wc -l)
if [ "$USEREXISTS" -ne 1 ]; then
echo "User '$1' with UID $2 not found in /etc/passwd"
echo "Aborted"
exit 1
fi
UIDEXISTS=$(cat /etc/passwd | grep -e "[^:]*:[^:]*:$3" | wc -l)
if [ "$UIDEXISTS" -ne 0 ]; then
echo "UID $3 already exists."
echo "Aborted"
exit 1
fi
# start modifiyng
usermod -u $3 $1
find / -user $2 -exec chown -h $3 {} \;
exit 0
fi
echo "
Contributor guide
Assessment
This issue has not been assessed yet.