我正在编写一个 bash 脚本来删除系统中不允许的用户,但我遇到了问题。
#!/bin/bash
getent passwd {1000..60000} | cut -d: -f1 > allusers.txt;
diff allowedusers.txt allusers.txt > del.user;
for user in "cat del.user";
do userdel -r $user;
done
当我运行它时,一切都很顺利,直到userdel
命令。它只输出userdel
.
Usage: userdel [options] LOGIN
Options:
-f, --force force removal of files,
even if not owned by user
-h, --help display this help message and exit
-r, --remove remove home directory and mail spool
-R, --root CHROOT_DIR directory to chroot into
-Z, --selinux-user remove any SELinux user mapping for the user
脚本运行后不会对用户进行任何更改。任何帮助,将不胜感激。
diff
产生具有找到差异的行数的结果:
:~$ cat 1
User1
User2
User3
$ cat 2
User233
User43
User234
User1
结果是:
$ diff 1 2
0a1,3
> User233
> User43
> User234
2,3d4
< User2
< User3
而不是diff
尝试grep
(以显示二维文件中的差异):
grep -v -F -x -f file1 file2
在哪里:
-F, --fixed-strings
Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.
-x, --line-regexp
Select only those matches that exactly match the whole line.
-v, --invert-match
Invert the sense of matching, to select non-matching lines.
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. The empty file contains zero patterns, and therefore matches nothing.
示例结果是:
$ grep -v -F -x -f 1 2
User233
User43
User234
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句