linux 开启curl命令,linux – 在脚本中只执行一次CURL命令?

为了解释一下,我正在监视文件夹中的任何更改,当检测到更改时,它只是通过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命令在每次检测和上传后已执行两次.

如果我忘记包含任何信息,请告诉我…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值