如何在crontab中运行我的curl bash脚本

时间:2018-10-10 17:03:10

标签: http curl influxdb

我有一些具有全局DNS负载平衡的HTTP服务器。现在,我想使用curl测量一些数据并将其保存到influxdb中,以便在所有服务器上的Grafana中创建一个简单的性能图。因此,我为此编写了一些bash脚本。在我的本地计算机上工作正常。但是,当我将其放在Ubuntu服务器14上并尝试将脚本作为cronjob运行时。我不能使它工作。有什么建议么? 脚本。

declare -a arr=("121.222.222.222@my-server","121.222.232.222@my-second-server")
dnsname="www.google.com" ## The adress i want to check
influddb="127.0.0.1:8086" ## my address to my influxdb

## now loop through the above array with servers
for i in "${arr[@]}"
do
      ##Split the name NAMES[0]=server ip, NAMES[1] = server name
      IFS='@' read -ra NAMES <<< $i    

      sURL=https://${NAMES[0]}/img/36090/r20-100KB.png;timestamp=$(date +%s%N);output=$(/usr/bin/curl -m 120 -Lo /dev/null -skw "%{time_connect}" -H " $dnsname" $sURL);/usr/bin/curl -XPOST http://$influddb/write?db=telegraf --data-binary "cdn-monitor-${NAMES[1]},type=time_connect data=$output $timestamp"
      sURL=https://${NAMES[0]}/img/36090/r20-100KB.png;timestamp=$(date +%s%N);output=$(/usr/bin/curl -m 120 -Lo /dev/null -skw "%{time_namelookup}" -H " $dnsname" $sURL);/usr/bin/curl -XPOST http://$influddb/write?db=telegraf --data-binary "cdn-monitor-${NAMES[1]},type=time_namelookup data=$output $timestamp"
      sURL=https://${NAMES[0]}/img/36090/r20-100KB.png;timestamp=$(date +%s%N);output=$(/usr/bin/curl -m 120 -Lo /dev/null -skw "%{time_pretransfer}" -H " $dnsname" $sURL);/usr/bin/curl -XPOST http://$influddb/write?db=telegraf --data-binary "cdn-monitor-${NAMES[1]},type=time_pretransfer data=$output $timestamp"
      sURL=https://${NAMES[0]}/img/36090/r20-100KB.png;timestamp=$(date +%s%N);output=$(/usr/bin/curl -m 120 -Lo /dev/null -skw "%{time_starttransfer}" -H " $dnsname" $sURL);/usr/bin/curl -XPOST http://$influddb/write?db=telegraf --data-binary "cdn-monitor-${NAMES[1]},type=time_starttransfer data=$output $timestamp"
      sURL=https://${NAMES[0]}/img/36090/r20-100KB.png;timestamp=$(date +%s%N);output=$(/usr/bin/curl -m 120 -Lo /dev/null -skw "%{time_redirect}" -H " $dnsname" $sURL);/usr/bin/curl -XPOST http://$influddb/write?db=telegraf --data-binary "cdn-monitor-${NAMES[1]},type=time_redirect data=$output $timestamp"
      sURL=https://${NAMES[0]}/img/36090/r20-100KB.png;timestamp=$(date +%s%N);output=$(/usr/bin/curl -m 120 -Lo /dev/null -skw "%{time_total}" -H " $dnsname" $sURL);/usr/bin/curl -XPOST http://$influddb/write?db=telegraf --data-binary "cdn-monitor-${NAMES[1]},type=time_total data=$output $timestamp"


done

脚本现在已更新,可在此处获得 Server monitor

0 个答案:

没有答案