gpt4 book ai didi

linux - Bash 脚本 : How to display output for the passwords expiry every 2 week

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:22:03 25 4
gpt4 key购买 nike

我的问题是,如何编辑脚本以便如果 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

最佳答案

您可以使用 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]+)的位置开始匹配

关于linux - Bash 脚本 : How to display output for the passwords expiry every 2 week,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41791300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com