我很难让这个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
答案 0 :(得分:1)
您的mail()
函数与mail命令的名称相同。
将mail()
重命名为mymailwrapper()
,否则只是递归调用自己。