【发布时间】:2010-12-08 09:07:41
【问题描述】:
我制作了一个 shell 脚本,它使用 ftp 协议获取远程文件,如果文件下载良好,它会在 php 中使用 curl 启动另一个脚本。它现在可以正常工作,但我有几个问题需要改进:
- 脚本是否正在等待下载结束以执行脚本的其余部分?或者在下载脚本期间执行以下指令?
- 我收到了第一封开始指令的邮件,但没有收到最后一封邮件(得到 curl 结果的邮件,以及脚本末尾的邮件)怎么会?
- 我想找到一种好方法来禁止脚本多次运行(如果已下载存档),即使它是使用 crontab 每隔几个小时启动一次?
- 在 ftp 连接结束时退出/再见/按有什么区别?
这是shell脚本:
echo start of the script | mail -s "beginning of the script" krifur@krifur.com
cd /my_rep
HOST='domaine.com'
PORT='21'
USER='admin'
PASSWD='pass'
jour=$(date "+%Y%m%d")
FILE="file_"$jour".txt";
ftp -i -n $HOST $PORT <<EOF
quote USER $USER
quote PASS $PASSWD
cd firstlevel
cd end
get $FILE
quit
EOF
if test -f $FILE
then
CurlRes="$(curl "http://doma.com/myfile.php")"
echo debug CURL : $CurlRes | mail -s "debug" krifur@krifur.com
else
echo no file : $FILE | mail -s "no file" krifur@krifur.com
fi
echo this is the end of the script download | mail -s "end of script download" krifur@krifur.com
【问题讨论】: