我是zenity的新手,想创建一个GUI来创建新用户和密码。我的代码是这样的:
#!/bin/bash
zenity --info --text='Welcome to Account Creation Wizard'
zenity --entry --text='What do you want to set your username as?' > username
zenity --password > test
cat username >> username1
cat username >> username1
cat test >> test1
cat test >> test1
useradd -m < username1
passwd < username1 < test1
rm test test1
rm username username1
exit
但它不起作用。在终端中,我得到这个:
[root@archevaris Desktop]# ./UserCreator.sh
Usage: useradd [options] LOGIN
useradd -D
useradd -D [options]
Options:
--badnames do not check for bad names
-b, --base-dir BASE_DIR base directory for the home directory of the
new account
--btrfs-subvolume-home use BTRFS subvolume for home directory
-c, --comment COMMENT GECOS field of the new account
-d, --home-dir HOME_DIR home directory of the new account
-D, --defaults print or change default useradd configuration
-e, --expiredate EXPIRE_DATE expiration date of the new account
-f, --inactive INACTIVE password inactivity period of the new account
-g, --gid GROUP name or ID of the primary group of the new
account
-G, --groups GROUPS list of supplementary groups of the new
account
-h, --help display this help message and exit
-k, --skel SKEL_DIR use this alternative skeleton directory
-K, --key KEY=VALUE override /etc/login.defs defaults
-l, --no-log-init do not add the user to the lastlog and
faillog databases
-m, --create-home create the user's home directory
-M, --no-create-home do not create the user's home directory
-N, --no-user-group do not create a group with the same name as
the user
-o, --non-unique allow to create users with duplicate
(non-unique) UID
-p, --password PASSWORD encrypted password of the new account
-r, --system create a system account
-R, --root CHROOT_DIR directory to chroot into
-P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files
-s, --shell SHELL login shell of the new account
-u, --uid UID user ID of the new account
-U, --user-group create a group with the same name as the user
New password: Retype new password: passwd: password updated successfully
[root@archevaris Desktop]#
它实际上所做的是更改我的root密码:P(这个 bash 脚本执行起来有点危险,但谢天谢地,我在 VM 快照中做到了(
那么,如何解决这个问题呢?我应该对代码进行哪些更改?
要通过zenity
获取用户名和密码,这将起作用:
export INFO=$(zenity --password --username)
$INFO将被管道分割,因此如果您的用户名是"Fred",密码是"123abc",$INFO将如下所示:
Fred|123abc
从这里开始,只需使用cut
来分隔数据:
USERNAME=$(echo $INFO | cut -d"|" -f1)
PASSWORD=$(echo $INFO | cut -d"|" -f2)