![Linux: yppasswd를 실행하여 passwd.byuid를 업데이트할 때 무작위로 실패하는 이유는 무엇입니까?](https://rvso.com/image/652682/Linux%3A%20yppasswd%EB%A5%BC%20%EC%8B%A4%ED%96%89%ED%95%98%EC%97%AC%20passwd.byuid%EB%A5%BC%20%EC%97%85%EB%8D%B0%EC%9D%B4%ED%8A%B8%ED%95%A0%20%EB%95%8C%20%EB%AC%B4%EC%9E%91%EC%9C%84%EB%A1%9C%20%EC%8B%A4%ED%8C%A8%ED%95%98%EB%8A%94%20%EC%9D%B4%EC%9C%A0%EB%8A%94%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
우리 회사의 NOC 사용자가 NIS를 통해 사용자를 관리할 수 있도록 다음 스크립트를 만들었습니다.
#!/bin/bash
# This script will simplicate NIS user management.
# You will not be able to change password or delete users peeradmin and root through this script.
# Written by Itai Ganot 2014.
# Edit only this variable:
PROTECTEDUSERS="peeradmin root" # Separate values with spaces.
# Variables
USER=$1
GREP="/bin/grep"
PASSWDFILE="/etc/passwd"
YPPASSWD="/usr/bin/yppasswd"
USERDEL="/usr/sbin/userdel"
USERADD="/usr/sbin/useradd"
PASSWD="/usr/bin/passwd"
YPCAT="/usr/bin/ypcat passwd.byname"
# Functions
function usage {
echo -e "Usage: $0 <username to manage>"
}
function updatenis {
echo -e "\e[36m #===# Uptdating NIS database... \e[0m"
cd /var/yp && make
}
# Script
if [ -z "$USER" ]; then
usage
exit 1
fi
if [ "$(id -u)" != "0" ]; then
echo -e "Run as root!"
exit 1
fi
"$GREP" -q "$USER" "$PASSWDFILE"
if [ "$?" = "0" ]; then
echo -e "\e[36m #===# User already exists \e[0m"
echo -e "\e[36m #===# How would you like to continue? \e[0m"
USERID=$(id -u $USER)
select CHOICE in 'Change user password' 'Remove user' 'View user' 'Exit'; do
case $CHOICE in
"Change user password")
if [[ "$PROTECTEDUSERS" =~ $USER ]]; then # Defense against changing root or peeradmin password
echo -e "\e[36m #===# User $USER should never be edited! \e[0m"
exit 1
fi
echo -e "\e[36m #===# Provide root password for NIS server... \e[0m"
"$YPPASSWD" "$USER"
updatenis
break
;;
"Remove user")
if [[ "$PROTECTEDUSERS" =~ $USER ]]; then # Defense against deletion of user root or peeradmin.
echo -e "\e[36m #===# User $USER should never be edited! \e[0m"
exit 1
fi
read -r -p "Remove home directory and mail? [y/n] " ANSWER1
if [[ "$ANSWER1" = [Yy] ]]; then
"$USERDEL" -r "$USER"
updatenis
echo -e "\e[36m #===# User $USER has been deleted along with the user's home folder and mail \e[0m"
break
else
"$USERDEL" "$USER"
echo -e "\e[36m #===# User $USER has been deleted \e[0m"
updatenis
break
fi
;;
"View user")
echo -e "\e[36m #===# Displaying user $USER \e[0m"
$YPCAT | $GREP "$USER"
break
;;
"Exit")
echo -e "\e[36m #===# Exiting, No changes done. \e[0m"
exit 0
;;
esac
done
else
read -r -p "User doesn't exist, would you like to add it? [y/n] " ANSWER2
if [[ "$ANSWER2" = [Yy] ]]; then
echo -e "\e[36m #===# Collecting required information... \e[0m"
sleep 2
LASTUID=$(tail -n 1 $PASSWDFILE | awk -F: '{print $3}')
NEXTUID=$(( LASTUID + 1 ))
$USERADD -g users $USER -u $NEXTUID
echo -e "\e[36m #===# Set password for the new user \e[0m"
$PASSWD $USER
updatenis
read -r -p "Would you like to test the creation of the user? [y/n] " ANSWER3
if [[ "$ANSWER3" = [Yy] ]]; then
$YPCAT | $GREP "$USER"
if [ "$?" = "0" ]; then
echo -e "\e[36m #===# User $USER created successfully! \e[0m"
fi
fi
elif [[ "$ANSWER2" = [Nn] ]]; then
echo -e "\e[36m #===# Exiting, no changes done. \e[0m"
exit 0
fi
fi
일반적으로 스크립트는 완벽하게 작동합니다. 예:
[root@nis ~]# Nis_Manage
Usage: /usr/sbin/Nis_Manage <username to manage>
[root@nis ~]# Nis_Manage itaig
#===# User already exists
#===# How would you like to continue?
1) Change user password 3) View user
2) Remove user 4) Exit
#? 1
#===# Provide root password for NIS server...
Changing NIS account information for itaig on nis.sj.company.com.
Please enter root password:
Changing NIS password for itaig on nis.sj.company.com.
Please enter new password:
Please retype new password:
The NIS password has been changed on nis.sj.company.com.
#===# Uptdating NIS database...
gmake[1]: Entering directory `/var/yp/company'
Updating passwd.byname...
Updating passwd.byuid...
Updating netid.byname...
gmake[1]: Leaving directory `/var/yp/company'
[root@nis ~]#
그러나 스크립트가 작동하는 다른 경우와 구별할 수 없는 경우가 있는데 실패하고 make
새 비밀번호로 NIS를 업데이트합니다.
[root@nis ~]# Nis_Manage itaig
#===# User already exists
#===# How would you like to continue?
1) Change user password 3) View user
2) Remove user 4) Exit
#? 1
#===# Provide root password for NIS server...
Changing NIS account information for itaig on nis.sj.company.com.
Please enter root password:
Changing NIS password for itaig on nis.sj.company.com.
Please enter new password:
Please retype new password:
The NIS password has been changed on nis.sj.company.com.
#===# Uptdating NIS database...
gmake[1]: Entering directory `/var/yp/company'
Updating passwd.byname...
Updating passwd.byuid...
makedbm: Cannot open passwd.byuid~
gmake[1]: *** [passwd.byuid] Error 1
gmake[1]: Leaving directory `/var/yp/company'
make: *** [target] Error 2
[root@nis ~]#
트렌드를 찾으려고 노력했지만 아무것도 찾을 수 없습니다. 업데이트가 무작위로 실패하는 이유를 찾아보실 수 있나요 passwd.byuid
?
미리 감사드립니다