Bash Maldet cron.daily脚本语法错误

Bash Maldet cron.daily脚本语法错误,bash,cron,Bash,Cron,我从服务器上的cron deamon收到一封带有语法bash错误的电子邮件,如: /etc/cron.daily/maldet: line 29: syntax error near unexpected token `fi' /etc/cron.daily/maldet: line 29: `fi' 我尝试了一些修改,但没有成功,bash不是我的强项。 cron每日文件: #!/usr/bin/env bash export PATH=/bin:/sbin:/usr/bin:/usr/sbi

我从服务器上的cron deamon收到一封带有语法bash错误的电子邮件,如:

/etc/cron.daily/maldet: line 29: syntax error near unexpected token `fi'
/etc/cron.daily/maldet: line 29: `fi'
我尝试了一些修改,但没有成功,bash不是我的强项。 cron每日文件:

#!/usr/bin/env bash
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
export LMDCRON=1
. /usr/local/maldetect/conf.maldet
if [ -f "/usr/local/maldetect/conf.maldet.cron" ]; then
    . /usr/local/maldetect/conf.maldet.cron
fi
find=`which find 2> /dev/null`
if [ "$find" ]; then
    # prune any quarantine/session/tmp data older than 7 days
    tmpdirs="/usr/local/maldetect/tmp /usr/local/maldetect/sess /usr/local/maldetect/quarantine /usr/local/maldetect/pub"
    for dir in $tmpdirs; do
     if [ -d "$dir" ]; then
      $find $dir -type f -mtime +7 -print0 | xargs -0 rm -f >> /dev/null 2>&1
     fi
    done
fi

if [ "$autoupdate_version" == "1" ] || [ "$autoupdate_signatures" == "1" ]; then
    # sleep for random 1-999s interval to better distribute upstream load
    sleep $(echo $RANDOM | cut -c1-3) >> /dev/null 2>&1
fi

if [ "$autoupdate_version" == "1" ]; then
    # check for new release version
    /usr/local/maldetect/maldet -d >> /dev/null 2>&1
fi

if [ "$autoupdate_signatures" == "1" ]; then
    # check for new definition set
    /usr/local/maldetect/maldet -u >> /dev/null 2>&1
fi
...

知道我为什么会得到这个吗?

根据bash-n脚本,所示脚本在语法上是正确的。
语法错误可能由错误的源脚本引起。bash-n/usr/local/maldetect/conf.maldet和bash-n/usr/local/maldetect/conf.maldet.cron说什么


如果这些都正常,可能是一个回车\r偷偷溜进某个地方?要进行测试,请运行od-c脚本并查找\r.

第29行将是…@Jens:if[$autoupdate_signatures==1];thenbash-n/usr/local/maldetect/conf.maldet不会输出与另一个相同的内容。使用od-c脚本无法看到任何\r…非常strange@calculataur嗯。下一步:删除查找=哪个部分。如果find在路径中,您不需要它,可以使用find$dir。。。。另外,将一个set-x作为!在脚本的第行中,删除所有指向/dev/null的重定向,并查看cron发送的邮件,这些邮件现在应该更加详细。有趣的是,第29行没有if语句。。。另外,将所有与==的比较更改为=,只有后者是可移植的。在重新启动和+x后,现在似乎可以工作。谢谢你的帮助。