gpt4 book ai didi

linux - 用于下载远程文件并启动的 shell 脚本以及用 PHP 编写的其他脚本

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:40:48 25 4
gpt4 key购买 nike

我制作了一个 shell 脚本,它使用 ftp 协议(protocol)获取远程文件,如果文件下载成功,它会在 php 中使用 curl 启动另一个脚本。它现在可以正常工作,但我有几个问题需要改进:

  • 脚本是在等待下载结束以执行脚本的其余部分?还是在下载脚本期间执行以下指令?
  • 我收到了开始指令的第一封邮件,但从来没有收到最后一封邮件(获得 curl 结果的邮件,以及脚本末尾的邮件)怎么回事?
  • 我想找到一种好方法来禁止脚本多次运行(如果存档已下载),即使它使用 crontab 每小时启动一次?
  • 在 ftp 连接结束时 quit/bye/by 有什么区别?

这是 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

最佳答案

Do the script is waiting the end of the download to execute the rest of the script ?Or during the time of download the script do the following instructions ?

如果您的意思是“FTP 命令会阻止直到完成吗?” ,答案是肯定的。

I receive the first mail of beginning instruction but never the last ones (the one that get the result of the curl, and the one at the end of the script) how come ?

看看你的代码:

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

$CurlRes 和$FILE 分别是什么内容?试试 ${CurlRes} 和 ${FILE}。我还建议在使用 echo 时引用字符串。

垃圾邮件过滤器也很可能不喜欢该邮件,您检查过了吗?

I would like to find a good way to disallow the script to be run more than once (if the archive has been downloaded) even if it's launch every hours with crontab ?

这可以通过多种方式实现。也许,成功后将文件名回显到 successfully_downloaded.txt 之类的底部,然后使用 grep 查看文件名是否在列表中。根据使用情况,该文件可能会变得相当大......所以我也会实现一些旋转它的方法。

来自 man (3) ftp:

bye         Terminate the FTP session with the remote server and exit ftp.
An end of file will also terminate the session and exit.


quit A synonym for bye.
据我所知,

by 也是 bye 的同义词。

关于linux - 用于下载远程文件并启动的 shell 脚本以及用 PHP 编写的其他脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4385742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com