帮助代表系统中的所有用户执行命令的实用程序
with-each-user的Python项目详细描述
每个用户的命令基本上只是一个快捷方式/替换 对于以下结构:
root:~# ls /home | xargs -i su - {} -c "whoami"
也就是说,它的目标是对系统中的所有用户执行相同的命令 在一行。上面的行可以重写为:
root:~# with_each_user whoami
此外,您还可以通过用户的登录名、外壳和 uid、同时以交互方式运行命令并存储脚本输出 在单独目录中的日志文件中。
有关详细信息,请参见用法。
用法
这是with_each_user --help输出:
usage: with_each_user [-h] [-m MASK] [-s SHELL] [-u MIN_UID] [-U MAX_UID] [-c CONCURRENCY] [-d CURRENT_DIRECTORY] [-i] [-L LOG_DIRECTORY] command [command ...] Execute a command for a number users in the server positional arguments: command Shell command to execute optional arguments: -h, --help show this help message and exit -m MASK, --mask MASK Filter users by their logins. Globbing is here allowed, you can type, for example, "user*" -s SHELL, --shell SHELL Filter users by their shells. For example, you can exclude the majority of system users by issuing "/bin/bash" here -u MIN_UID, --min-uid MIN_UID Filter users by their minimal uid. -U MAX_UID, --max-uid MAX_UID Filter users by their max uid (to filter out "nobody", for example -c CONCURRENCY, --concurrency CONCURRENCY Number of processes to run simultaneously -d CURRENT_DIRECTORY, --current-directory CURRENT_DIRECTORY Script working directory (relative to user's home) -p, --preserve-environment Preserve root environment. Arguments match the same of "su" command -f, --format Format command line with variables custom for every user. Supported variables: {user}, {uid}, {gid}, {home}, {shell}, {gecos}. -r, --root Run command with root privileges (do not "su" to selected user). Option "--format" is helpful there -i, --interactive Interactive execution. Set this flag to run processes interactively -L LOG_DIRECTORY, --log-directory LOG_DIRECTORY Directory to store log for all executions. Omit this argument if you want just to print everything to stdout/stderr