【问题标题】:Bash Scripting: How to display output for the passwords expiry every 2 weekBash 脚本:如何显示密码每 2 周到期的输出
【发布时间】:2017-06-07 01:47:18
【问题描述】:

我的问题是,我如何编辑脚本以使 如果 PASS_MAX_DAYS 等于或小于 14 天,那么它等于“漏洞:否”

Output

我的脚本

#!/bin/bash

passwordexpiry=`grep "^PASS_MAX_DAYS" /etc/login.defs`

if [[ $(passwordexpiry) == "PASS_MAX_DAYS    99999" ]]
then
      isVulnerable="Yes"
else 
      isVulnerable="No"
fi
  echo "Audit criteria: The passowrds expires every 2 weeks"
  echo "Vulnerability: ${isVulnerable}"
  echo "Details: See below"
  echo
  echo "Command:"
  echo "grep "^PASS_MAX_DAYS" /etc/login.defs"
  echo
  echo "Output:"
  echo ${passwordexpiry}
  echo

【问题讨论】:

    标签: linux bash scripting audit


    【解决方案1】:

    您可以使用grep -oP "^PASS_MAX_DAYS\s+\K([0-9]+)" /etc/login.defs 提取值:

    #!/bin/bash
    
    max=14
    passwordexpiry=`grep -oP "^PASS_MAX_DAYS\s+\K([0-9]+)" /etc/login.defs`
    
    if [ "$passwordexpiry" -le "$max" ]
    then
          isVulnerable="No"
    else 
          isVulnerable="Yes"
    fi
    
    echo "$isVulnerable"
    

    \K从值([0-9]+)的位置开始匹配

    【讨论】:

      猜你喜欢
      • 2020-02-16
      • 2018-07-07
      • 2018-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多