我试图创建一个脚本,它使测试用户具有主dir和他需要的权限,但是每次运行该脚本时,我都会得到以下错误:
/home/thomas/Scripts/CreateUser.sh: line 2: useradd: command not found
passwd: user 'password' does not exist
/home/thomas/Scripts/CreateUser.sh: line 4: mkhomedir_helper: command not found
chmod: cannot access ‘/home/Test/’: No such file or directory剧本:
#!/bin/bash
useradd Test
passwd password
mkhomedir_helper Test
chmod 700 /home/Test/我对linux很陌生,所以我不知道为什么会出现这种情况,有什么解决方案吗?
发布于 2017-02-03 12:07:46
您的脚本应该如下所示:
#!/bin/bash
/usr/sbin/useradd -m -d /home/Test/ -s /bin/bash Test
echo -e "password\npassword" | passwd Test
chmod 700 /home/Test/导致错误的原因是,/usr/sbin很可能不在运行脚本的帐户的$PATH变量中。
https://unix.stackexchange.com/questions/342239
复制相似问题