挂在邮件函数上的Shell脚本

挂在邮件函数上的Shell脚本,shell,Shell,我很难运行这个shell脚本。我决定在我的脚本中开始使用简单的函数,因为它更具可读性和可维护性。这是我第一次尝试,一切都运行得很好,但邮件功能挂起。我知道邮件等待EOF,但我正在使用echo将我的身体输送到邮件中 我想我在shell脚本中引用或部分传递我不完全理解的参数时犯了一些错误。我尝试了我能想到的所有引用组合,但每次都挂起 #!/bin/bash if [ -f /tmp/imports ] then echo "Script Off" exit fi

我很难运行这个shell脚本。我决定在我的脚本中开始使用简单的函数,因为它更具可读性和可维护性。这是我第一次尝试,一切都运行得很好,但邮件功能挂起。我知道邮件等待EOF,但我正在使用echo将我的身体输送到邮件中

我想我在shell脚本中引用或部分传递我不完全理解的参数时犯了一些错误。我尝试了我能想到的所有引用组合,但每次都挂起

#!/bin/bash

if [ -f /tmp/imports ]
then
        echo "Script Off"
        exit
fi

OLDIFS=$IFS
IFS=$'\n'
IFS=$OLDIFS
LOGFILE="/var/log/file.log"

log(){
        DATE=`date "+%m-%d-%Y %H:%M"`
        MESSAGE="$DATE - $@"

        echo $MESSAGE
        echo $MESSAGE >>$LOGFILE
}

mail(){
        BODY="$1"
        SUBJECT="$2"

        echo "$BODY" |  mail -s "$SUBJECT" my@email.com
}

log "Script Started"

TodayFiles=`find /ftpfiles/incoming/ -type f -mmin +60`
Count=`find /ftpfiles/incoming/ -type f -mmin +60 | wc -l`

log "$Count Files Found"

if [ $Count -gt 4 ]; then
        log "Too Many Files!!!\n"
        mail "There were 5 or more files found by the script. I have not moved any files at this time. There is likely something very wrong. Please check things out immediately." "ATTN: TOO MANY FILES!"

fi

if [ $Count -gt 0 ]; then
        log "Scanning Files..."
        for Source in $TodayFiles
        do
                log "Found file: $Source"
                #mv "$Source" "/ftpfiles/rejected$Source"
                log "Moved file to: /ftpfiles/rejected$Source"
                mail "The file $Source has been moved to rejected. Please find out why and send the proper rejection. Thank You." "ATTN: Stranded Import file Found"
        done
fi
mail()
函数与mail命令具有相同的名称。
mail()
重命名为类似于
mymailwrapper()
的名称,否则它只是在递归地调用自己。

谢谢,我之前就知道了。这是一个面部手掌的瞬间