i found script measuring speed , send via curl. unfortunately, script not work , not know why.
advise anyone?
pi@raspberrypi:~$ sh speedtest-ifttt.sh
speedtest-ifttt.sh: 21: speedtest-ifttt.sh: syntax error: "(" unexpected
advise anyone?
pi@raspberrypi:~$ sh speedtest-ifttt.sh
speedtest-ifttt.sh: 21: speedtest-ifttt.sh: syntax error: "(" unexpected
code: select all
#!/usr/bin/env bash ########################################################################### # written by: henrik bengtsson, 2014 # https://github.com/henrikbengtsson/speedtest-cli-extras # modified use ifttt by: alasdair allan, 2015 # license: gpl (>= 2.1) [http://www.gnu.org/licenses/gpl.html] ########################################################################### # character separating values # (commas not safe, because servers return speeds commas) sep=";" # temporary file holding speedtest-cli output user=$user if test -z $user; user=$username fi log=/tmp/$user/speedtest-csv.log # local functions function str_extract() { pattern=$1 # extract res=`grep "$pattern" $log | sed "s/$pattern//g"` # drop trailing ... res=`echo $res | sed 's/[.][.][.]//g'` # trim res=`echo $res | sed 's/^ *//g' | sed 's/ *$//g'` echo $res } # display header? if test "$1" = "--header"; start="start" stop="stop" from="from" from_ip="from_ip" server="server" server_dist="server_dist" server_ping="server_ping" download="download" upload="upload" share_url="share_url" else mkdir -p `dirname $log` start=`date +"%y-%m-%d %h:%m:%s"` if test -n "$speedtest_csv_skip" && test -f "$log"; # reuse existing results (useful debugging) 1>&2 echo "** reusing existing results: $log" else # query speedtest /usr/local/bin/speedtest-cli --share > $log fi stop=`date +"%y-%m-%d %h:%m:%s"` # parse from=`str_extract "testing "` from_ip=`echo $from | sed 's/.*(//g' | sed 's/).*//g'` from=`echo $from | sed 's/ (.*//g'` server=`str_extract "hosted "` server_ping=`echo $server | sed 's/.*: //g'` server=`echo $server | sed 's/: .*//g'` server_dist=`echo $server | sed 's/.*\\[//g' | sed 's/\\].*//g'` server=`echo $server | sed 's/ \\[.*//g'` download=`str_extract "download: "` upload=`str_extract "upload: "` share_url=`str_extract "share results: "` fi # standardize units? if test "$1" = "--standardize"; download=`echo $download | sed 's/mbits/mbit/'` upload=`echo $upload | sed 's/mbits/mbit/'` fi # send ifttt secret_key="secret_key" value1=`echo $server_ping | cut -d" " -f1` value2=`echo $download | cut -d" " -f1` value3=`echo $upload | cut -d" " -f1` json="{\"value1\":\"${value1}\",\"value2\":\"${value2}\",\"value3\":\"${value3}\"}" curl -x post -h "content-type: application/json" -d "${json}" https://maker.ifttt.com/trigger/speedtest/with/key/${secret_key}
the script intended interpreted bash, not sh.napajedlaci.cz wrote:pi@raspberrypi:~$ sh speedtest-ifttt.sh
speedtest-ifttt.sh: 21: speedtest-ifttt.sh: syntax error: "(" unexpected
not understand why people insist on writing non-posix shell scripts. in case extraneous word "function" on line 21 may thing preventing script being portable.
raspberrypi
Comments
Post a Comment