亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標題: 為啥報 readonly variable [打印本頁]

作者: 338378WN8    時間: 2013-05-06 14:16
標題: 為啥報 readonly variable
寫了一個腳本,用于將一臺服務(wù)器上的USER信息復(fù)制到另一臺上的。(一個suse,一個rhel)

while read USER UID GID DIR SH PASSWD
do
useradd -m -d $DIR -u $UID -g $GID -s $SH $USER
echo -e "$PASSWD\n$PASSWD\n" |passwd $USER
done < ftp_userpassword.txt

more [root@lxbftp01 ~]# more ftp_userpassword.txt
user1 1001    100     /ftp/user1   /bin/bash       passwd1
user2   1002    100     /ftp/user2       /bin/bash       passwd2
user3   1003    100     /ftp/user3      /bin/bash       passwd3


結(jié)果卻是一直報錯
./add_ftpuser.sh
./add_ftpuser.sh: line 5: UID: readonly variable
useradd: UID 0 is not unique
passwd: Unknown user name 'user1'.
./add_ftpuser.sh: line 5: UID: readonly variable
useradd: UID 0 is not unique
passwd: Unknown user name 'user2'.
./add_ftpuser.sh: line 5: UID: readonly variable
useradd: UID 0 is not unique
passwd: Unknown user name 'user3'.

奇怪的是,UID和GID都是數(shù)字,但是一個報錯,一個正常,用bash -x 方式執(zhí)行,可以看到gid都被正常賦值
+ read USER UID GID DIR SH PASSWD
add_ftpuser.sh: line 5: UID: readonly variable
+ useradd -m -d /ftp/user1 -u 0 -g 100 -s /bin/bash user1
useradd: UID 0 is not unique

請高手指點
作者: nbrr    時間: 2013-05-06 14:22
本帖最后由 nbrr 于 2013-05-06 14:27 編輯

看abs, bash internal variables
http://tldp.org/LDP/abs/html/internalvariables.html
This is the current user's real id, even if she has temporarily assumed another identity through su. $UID is a readonly variable, not subject to change from the command line or within a script,

你可以換個名字
while read ftpUSER ftpUID ftpGID ftpDIR ftpSH ftpPASSWD

作者: 338378WN8    時間: 2013-05-06 14:38
nbrr 發(fā)表于 2013-05-06 14:22
看abs, bash internal variables
http://tldp.org/LDP/abs/html/internalvariables.html
This is the cur ...


原來是和原有的變量重名了,多謝




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2