我正在编写一个bash脚本,该脚本删除系统中不允许的用户,但是我遇到了问题。
only references to parameters are allowed in contract description
当我运行它时,一切进展顺利,直到#!/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
脚本运行后,不对用户进行任何更改。任何帮助将不胜感激。
答案 0 :(得分:0)
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
(以显示2d文件中的差异):
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
答案 1 :(得分:-1)
您的user
变量未遍历文件中的用户。它遍历原义字符串“ cat del.user”,而不是文件del.user的内容。
要获取文件的内容,我相信您打算使用子外壳来管理文件:
for user in $(cat del.user); do
userdel -r $user
done