为了解释一下,我正在监视文件夹中的任何更改,当检测到更改时,它只是通过rsync将检测到的文件上传到我的服务器.这没有任何问题:
#!/bin/bash
time_stamp=$(date +"%B-%d-%Y")
inotifywait -mr /usr/lib/unifi-video/data/videos -e create -e moved_to |
while read path action file; do
echo "The file '$file' appeared in directory '$path' via '$action'"
rsync -avz -e "ssh -p 221" /$path/$file username@myserver.com:~/"$time_stamp"/
done
问题:我正在尝试将以下CURL行添加到上面的脚本中,但是由于一次检测到多个文件,它也会多次执行CURL行.我试图找到一种方法来防止CURL行在检测到多个文件时被多次执行?
curl http://textbelt.com/text -d number=XXXXXXX -d "message=Motion Detected";
我尝试直接在rsync命令下添加它作为新行,以及使用&&在rsync命令之后.两种方法都多次执行CURL命令.
我试过的例子:
#!/bin/bash
time_stamp=$(date +"%B-%d-%Y")
inotifywait -mr /usr/lib/unifi-video/data/videos -e create -e moved_to |
while read path action file; do
echo "The file '$file' appeared in directory '$path' via '$action'"
rsync -avz -e "ssh -p 221" /$path/$file username@myserver.com:~/"$time_stamp"/
curl http://textbelt.com/text -d number=XXXXXXX -d "message=Motion Detected";
done
输出示例:
The file 'test30' appeared in directory '/usr/lib/unifi-video/data/videos/' via 'CREATE'
sending incremental file list
sent 39 bytes received 11 bytes 20.00 bytes/sec
total size is 0 speedup is 0.00
{
"success": true
}
The file 'test31' appeared in directory '/usr/lib/unifi-video/data/videos/' via 'CREATE'
sending incremental file list
sent 39 bytes received 11 bytes 20.00 bytes/sec
total size is 0 speedup is 0.00
{
"success": true
}
两条“成功”行显示CURL命令在每次检测和上传后已执行两次.
如果我忘记包含任何信息,请告诉我…