【问题标题】:Bash Script reporting members of a groupBash 脚本报告组的成员
【发布时间】:2016-09-19 10:39:20
【问题描述】:

我需要能够使用 bash 创建一个脚本,该脚本将报告特定组的成员(用户在该组中),将输出写入文件并使用 crontab 来安排脚本

我已经完成了 Crontab 部分,但不确定这是否也正确:

 - 5:55am: 55 5 * * 1-5 /bin/sh /home/test/membersofgroup.sh 
 - 9:55am: 55 9 * * 1-5 /bin/sh /home/test/membersofgroup.sh
 - 3:55pm: 55 15 * * 1-5 /bin/sh /home/test/membersofgroup.sh

问候。

【问题讨论】:

  • 我假设- 5:55am: 实际上不在 crontab 中,您只是在此处使用它来进行解释。如果这是正确的,那么你所拥有的看起来是正确的。但是 SO 不是向crontab 寻求帮助的合适地方,unix.stackexchange.com 是一个更好的地方。
  • 您可以将它们组合成一行:55 5,9,15 * * 1-5 /bin/sh /home/tycho/membersofgroup.sh
  • 您可以列出用户:awk -F\: '/^specific:/ {print $4}' /etc/group > file.txt。输出将类似于:user1,user2,user3 ....
  • @Barmar 谢谢!我将前往 unix.stackexchange.com 并在那里询问。
  • @JamesBrown 所以我将它添加到 .sh 文件中?

标签: linux bash shell cron


【解决方案1】:

将@Barmar 的crontab 条目与我的awk 结合起来:

$ cat >> crontab_file_of_yours.txt
55 5,9,15 * * 1-5 awk -F\: '/^specific:/ && $0=$4' /etc/group >> /pathto/file.txt
$ crontab crontab_file_of_yours.txt

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-23
    • 2020-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-26
    • 1970-01-01
    相关资源
    最近更新 更多