Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基本Bash脚本过早退出。直到半小时前,他还工作得很好_Bash - Fatal编程技术网

基本Bash脚本过早退出。直到半小时前,他还工作得很好

基本Bash脚本过早退出。直到半小时前,他还工作得很好,bash,Bash,我有一个有趣的问题,我似乎想不出来 我有一个基本脚本,可以提取配置信息并将其重定向到文件: cat/etc/something>1 cat/etc/other>2 数据收集完成后,我会运行一个“解析器”,提供有关检查的信息: #58 id="RHEL-06-000001" ruleid="The system must require passwords to contain at least one special character." if grep -G [a-z] 1; then

我有一个有趣的问题,我似乎想不出来

我有一个基本脚本,可以提取配置信息并将其重定向到文件:

cat/etc/something>1

cat/etc/other>2

数据收集完成后,我会运行一个“解析器”,提供有关检查的信息:

#58

id="RHEL-06-000001"
ruleid="The system must require passwords to contain at least one special character."
if grep -G [a-z] 1; then
    ocredit=`cat 1 | grep -v "^#" | awk '{print $2}'`
    if [ "$ocredit" -le -1 ]; then
            result="Not A Finding"
            todo="None"
    else
            result="Open"
            todo="The current value is $ocredit. This is less than the minimum requirement of -     1."
    fi
else
    result="Open"
    todo="The option is not configured"
fi
echo "$id, $ruleid, $result, $todo" >> Findings.csv

#59

id="RHEL-06-000002"
ruleid="The system must require passwords to contain at least one lowercase alphabetic     character."
if grep -G [a-z] 2; then
    lcredit=`cat 2 | awk -F"=" '{print $2}'`
    if [ "$lcredit" -le -1 ]; then
            result="Not A Finding"
            todo="None"
    else
            result="Open"
            todo="The current value is $lcredit. This is less than the minimum requirement of -1."
    fi
else
    result="Open"
    todo="The system is not configured to require at least one lowercase alphabetical charatcer in passwords."
echo "$id, $ruleid, $result, $todo" >> Findings.csv
或者是一些与之非常接近的东西

我大约有250次这样的检查,但我的代码是先运行前58次,然后停止,不再将内容重定向到checks.csv

在脚本提前完成后,我确实会收到一个错误,声明
/checker.sh:第2898行:语法错误:文件意外结束
这是我的文件的结尾,但我似乎不知道它是如何在脚本中转义到这一点的

踢球的人,这一切直到大约半小时前才见效,现在已经被难倒了


你能帮我一下吗?

这可能意味着你有一个未关闭的
if
语句或类似语句。Bash按需读取简单命令,但当遇到这样的复杂语句时,它希望读取整个
if
语句及其内容。如果它在试图读取到EOF的末尾时遇到EOF,它将给您该错误。

这可能意味着您有一个未关闭的
If
语句或类似语句。Bash按需读取简单命令,但当遇到这样的复杂语句时,它希望读取整个
if
语句及其内容。如果它在继续读取到最后一行时遇到EOF,它将给您该错误。

您似乎缺少最后一行之后的
fi

else
    result="Open"
    todo="The system is not configured to require at least one lowercase alphabetical charatcer in passwords."
## HERE ##
echo "$id, $ruleid, $result, $todo" >> Findings.csv

这可能会在遇到bash解析器时导致问题,当
bash
尝试查找缺少的
fi
时,会导致EOF错误。您似乎在第二行之后缺少了
fi

else
    result="Open"
    todo="The system is not configured to require at least one lowercase alphabetical charatcer in passwords."
## HERE ##
echo "$id, $ruleid, $result, $todo" >> Findings.csv

这可能会在遇到bash解析器时导致问题,在
bash
尝试查找缺少的
fi

时会导致EOF错误,请尝试在
[a-z]
周围添加引号。我打赌你在当前目录中创建了一个单字母名称的文件。第2898行?这是一个地狱般的脚本…哈哈,一定是一个脚本。不允许编译代码。我将尝试引号,这是一个漫长的夜晚引号没有起作用。我还有很多没有它的代码段运行良好。请尝试在
[a-z]
周围添加引号。我打赌你在当前目录中创建了一个单字母名称的文件。第2898行?这是一个地狱般的脚本…哈哈,一定是一个脚本。不允许编译代码。我将尝试引号,这是一个漫长的夜晚引号没有起作用。我有很多其他没有它的代码段运行得很好,所以这可能不是所展示的代码的问题,而是在它之前运行的代码的问题。我在这个脚本中有几个“复杂”的命令。有很多地方会让它误入歧途,所以它可能不是呈现的代码的问题,而是在它之前运行的代码的问题。我在这个脚本中有几个“复杂”的命令。有很多地方让它误入歧途。太棒了。我只需要第二双眼睛。非常感谢!好极了我只需要第二双眼睛。非常感谢!