我正在尝试将生成的文件移动到它的适当目录。当我不使用案件时,它将文件移到正确的目录就好了。但是,既然我要根据情况为它引入不同的参数,它甚至不再移动文件。如评论中所述,我没有任何错误。我的日志中没有看到问题
#!/bin/bash
#---------------------------------------------------------------------------------
# The statement below includes the batch path directories.
daily="/POO/fos/File_Ordering_Logs/Daily"
weekly="/POO/fos/File_Ordering_Logs/Weekly"
monthly="/POO/fos/File_Ordering_Logs/Semiannually"
spoolFilterDir="/POO/fos/spool_error_chk"
_endDate=$(date +"%m%d%Y")
_day=$(date +"%u")
#------------------------------------------------------------------------
case "$1" in
(daily)
directory=$daily
_beginDate=$(date -d "1 day ago" +"%m%d%Y")
report="$_endDate"DailyFOSReport".csv"
;;
(weekly)
directory=$weekly
_beginDate=$(date -d "7 days ago" +"%m%d%Y")
report="$_beginDate-$_endDate"WeeklyFOSReport".csv"
;;
(monthly)
directory=$monthly
_beginDate=$(date -d "183 days ago" +"%m%d%Y")
report="$_beginDate-$_endDate"SemiAnnualFOSReport".csv"
;;
esac
touch "$spoolFilterDir/$report"
#------------------------------------------------------------------------
# Error filter
#
exec_error_filter()
{
cd $spoolFilterDir
grep --include "*.csv" -e "ERROR" -e^SELECT -e^TNS -e^SP2 -e^ORA ${spoolFilterDir}/${report}
greprc=$?
if [[ $greprc -eq 0 ]] ; then
echo "--------------------------------"
echo "Erroneous data spooled to .csv report. Removing report."
echo "--------------------------------"
rm ${spoolFilterDir}/${report}
else
echo "FOS report successfully generated."
fi
case "daily" in
(daily)
mv ${spoolFilterDir}/${report} $daily
;;
(weekly)
mv ${spoolFilterDir}/${report} $weekly
;;
(monthly)
mv ${spoolFilterDir}/${report} $monthly
;;
esac
}
#-----------------------------------------------------------------------------
#END
答案 0 :(得分:0)
您的错误在这里:
case "daily" in ### <- always hardcoding the word "daily"
(daily)
mv ${spoolFilterDir}/${report} $daily
;;
(weekly)
mv ${spoolFilterDir}/${report} $weekly
;;
(monthly)
mv ${spoolFilterDir}/${report} $monthly
;;
esac
我想你的意思是
case "$1" in
(daily)
mv ${spoolFilterDir}/${report} $daily
;;
(weekly)
mv ${spoolFilterDir}/${report} $weekly
;;
(monthly)
mv ${spoolFilterDir}/${report} $monthly
;;
esac
您编写代码的方式无论如何都将始终属于“每日”情况。
除此之外,您的函数exec_error_filter
不会在任何地方调用。这也可以解释为什么什么都没发生。