这是一个两部分的问题。
场景:这个脚本在一个 cronjob 上。如果文件夹不存在,系统会向我们发送一封电子邮件,其中会打开一张票,通知我们该文件夹不可用。我们必须手动登录并删除前面的文件夹 atm。
我希望我们能够手动执行脚本并通过按“Y”删除前面的文件夹,或者在我们登录并手动执行脚本时按“Enter”键继续。
这是我到目前为止...
#-- check to see if cache folder exists
{ echo "Checking to see if ...";
echo "${wDir}/${client%/}/.ftp-vendor-scripts/cache exists ... "; echo ""; } >> "$log"
if [ ! -d "${wDir}"/"${client%/}"/.ftp-vendor-scripts/cache ]; then
echo "Directory - ${wDir}/${client%/}/.ftp-vendor-scripts/cache DOES NOT exists - Failed ..." >> "$log";
if [ ******** this script is being executed manually ******* ]; then
echo "Would you like to delete the ${wDir}/${client%/}/.ftp-vendor-scripts folder?"
echo "Press \"Y\" to delete the ${wDir}/${client%/}/.ftp-vendor-scripts."
echo "Press \"Enter\" to continue without deleting the .ftp-vendor-scripts folder."
else
echo "Directory - ${wDir}/${client%/}/.ftp-vendor-scripts/cache DOES NOT exists - Failed ..." | mail -s "${wDir}/${client%/}/.ftp-vendor-scripts/ca$
fi
else
echo "Directory - ${wDir}/${client%/}/.ftp-vendor-scripts/cache exists - Success ..." >> "$log";
fi
你需要这样的东西:
上面的脚本是 -
POSIX
兼容的,并检查了shellcheck
. 它将检查它是否在interactive
或non interactive
模式下运行,可能通过cron
并会采取相应的行动。我已经用bash
,dash
和对其Busybox ash
进行了测试FreeBSD
。