我如何在此脚本中输出命令的结果?

问题描述 投票:0回答:1
if [ "$(stat -c "%a" /etc/crontab)" == "644" ]
then
  echo "Is there a vulnerability: No, Permission set on /etc/crontab file is correct."
else
  echo "Is there a vulnerability: Yes, Permission set on /etc/crontab file is incorrect. echo awk -F: $(stat -c "%a" /etc/crontab)"
fi

这是我正在使用的审核脚本,如果不等于chmod 644,我想输出/ etc / crontab文件的当前权限。我尝试了许多方法都没有用。如果重要的话,我正在RHEL 7服务器中执行此操作。

bash echo rhel7
1个回答
0
投票

比较bash中的数字时,应使用-eq而不是==。因此,您的if来自此:

if [ "$(stat -c "%a" /etc/crontab)" == "644" ]

必须

if [ "$(stat -c "%a" /etc/crontab)" -eq "644" ]
© www.soinside.com 2019 - 2024. All rights reserved.