如果python脚本在获得异常时返回非零错误级别,则可以使用|| {}记录消息:
./scriptA.py < "$file" || {
printf "\n Python script scriptA.py failed with file \"%s\".\n" "$file" >> shelltestlog.txt
}
我实际上试图首先简化你的代码:
#!/bin/bash
yesterday=$(date --date "yesterday" "+%y%m%d")
ftoday=$(date --date "today" "+%m-%d-%Y")
year=$(date "+%Y")
readarray -t filesList <
for file in "${filesList[@]}"; do
printf "\n START Processing File : %s\n" "$file" >> shelltestlog.txt
./scriptA.py < "$file" || {
printf "\n Python script scriptA.py failed with file \"%s\".\n" "$file" >> shelltestlog.txt
}
printf "\n END Processing File : %s\n" "$file" >> shelltestlog.txt
done