我正在研究一个 bash 脚本,该脚本仅在远程时间戳与本地时间戳不同时才从 FTP 站点提取文件。放置文件后,它通过 samba (smbclient) 将文件复制到其他 3 台计算机。
一切正常,但即使 wget -N ftp://insertsitehere.com返回的值表明远程文件不是更新的,文件也会复制。检查脚本输出的最佳方法是什么,以便仅在从 FTP 提取新版本时才会发生副本?
理想情况下,我希望复制到计算机以保留时间戳,就像 wget -N 命令一样。
这是我所拥有的一个例子:
#!/bin/bash
OUTDIR=/cats/dogs
cd $OUTDIR
wget -N ftp://user:password@sitegoeshere.com/filename
if [ $? -eq 0 ]; then
HOSTS="server1 server2 server3"
for i in $HOSTS; do
echo "Uploading to $i..."
smbclient -A /root/.smbclient.authfile //$i/path -c "lcd /cats/dogs; put fiilename.txt"
if [ $? -eq 0 ]; then
echo "Upload to $i successful..."
else
echo "There was an issue uploading to host $i..."
fi
done
else
echo "There was an issue with the FTP Download...."
exit 1
fi