I tested the script and when i start it it works fine. But when starting the script in cron, nothing happens. I can see the output.tx file is being updated but the info in the html page of domoticz is not updated. Also starting with sudo in cron doesn't help.
Does anyone know why ?
the same for me the script works fine but not the crontab, any idea ?
If you use cron, be sure to make all external command with full path.
So replace ping with
/bin/ping
Replace curl with
/usr/bin/curl
Replace speedtest-cli with
/usr/bin/speedtest-cli
This is the short answer.
The long answer is that cron will passes a minimal set of environment variables to your jobs. In most cases it will not know the current PATH, so it will not find the external commands. There are lots of ways how to work around this, but if you use the full path, it will just work.
p.s. if you don't know the full path, just type in "which {command}" and you will find the full path.
Weird that you get errors on 'empty' lines and commented out lines (with the #).
My guess would be invisible weird characters as well somehow. Why don't you just paste your created script (local) into nano (remote) in a terminal? That usually works for me.
Next to that, what happens if you run it with ./st2domo.sh instead of sh st2domo ?
And, did you install speedtest-cli?
It's such a simple script, what can possibly go wrong hehe
#!/bin/bash
#setup
host=192.168.10.137
port=8080
username=mijn gebruikersnaam
password=mijn password
pingidx=27
downloadidx=28
uploadidx=29
# no need to edit
speedtest-cli --simple > output.txt
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
download=$(cat output.txt | sed -ne 's/^Download: \([0-9]*\.[0-9]*\).*/\1/p')
upload=$(cat output.txt | sed -ne 's/^Upload: \([0-9]*\.[0-9]*\).*/\1/p')
#output if you run it manually
echo "ping = $ping ms"
echo "download = $download Mbps"
echo "upload = $upload Mbps"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice&idx=$pingidx&svalue=$ping"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice&idx=$downloadidx&svalue=$download"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice&idx=$uploadidx&svalue=$upload"
I have made the sh file in windows with notepad++ and upload it with ftp to the rasp.
When I check the file with for example nano editor in SSH i see no strange characters.
#!/bin/bash
#setup
host=192.168.10.137
port=8080
username=mijn gebruikersnaam
password=mijn password
pingidx=27
downloadidx=28
uploadidx=29
# no need to edit
speedtest-cli --simple > output.txt
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
download=$(cat output.txt | sed -ne 's/^Download: \([0-9]*\.[0-9]*\).*/\1/p')
upload=$(cat output.txt | sed -ne 's/^Upload: \([0-9]*\.[0-9]*\).*/\1/p')
#output if you run it manually
echo "ping = $ping ms"
echo "download = $download Mbps"
echo "upload = $upload Mbps"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice&idx=$pingidx&svalue=$ping"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice&idx=$downloadidx&svalue=$download"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice&idx=$uploadidx&svalue=$upload"
I have made the sh file in windows with notepad++ and upload it with ftp to the rasp.
When I check the file with for example nano editor in SSH i see no strange characters.
to /path to speedtest-cli/speedtest-cli --simple > output.txt
Still not working then there is as a told before a change with a problem with the file and wrong characters.
Try using WinSCP or Putty and nano and create a new file .
Past code in it and make it executable and try again.
I have for testing made an new file (test.sh) with nano from the terminal.
And insert the basic script and how strange it is, this works.
When I check the difference between the two files I see no different between it...
So I think that some were there is an hidden character or something..
phoenixblue wrote:I have for testing made an new file (test.sh) with nano from the terminal.
And insert the basic script and how strange it is, this works.
When I check the difference between the two files I see no different between it...
So I think that some were there is an hidden character or something..
#setup
host=192.168.135.100
port=8080
username=xxxxxxxx
password=xxxxxxxx
pingidx=60
downloadidx=61
uploadidx=62
# no need to edit
speedtest-cli --server 3667 > output.txt
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
download=$(cat output.txt | sed -ne 's/^Download: \([0-9]*\.[0-9]*\).*/\1/p')
upload=$(cat output.txt | sed -ne 's/^Upload: \([0-9]*\.[0-9]*\).*/\1/p')
#output if you run it manually
echo "ping = $ping ms"
echo "download = $download Mbps"
echo "upload = $upload Mbps"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice$
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice$
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice$
The line speedtest-cli --server 3667 > output.txt is not correct when you need ping. You need to add --simple
I adjust your script like mine so try this one.
hi guys, today i change my router from the tp-link to fritzbox.
and without take any change on the rpi2 this is my new result with the test. (i have a line with 10 dw and 1 up, in italy we are very poor with the lan structure !!!! hihihihi)
i think that the old router/modem/access point don't work very good as the new.
now the router work very good. bye bye.
I try to add internet connection monitor to my domoticz and face same problems.
First is that I cannot create virtual switch in the menu to create it, I'm asked to add info for "Axis Labels" can you please let me know what should be there.
Second issue is that in output.txt file is do see correct values:
But when I start manually st32domo.sh I have these values:
There is different description. Do you know what I did wrong ?
I try to add internet connection monitor to my domoticz and face same problems.
First is that I cannot create virtual switch in the menu to create it, I'm asked to add info for "Axis Labels" can you please let me know what should be there.
Second issue is that in output.txt file is do see correct values:
But when I start manually st32domo.sh I have these values:
There is different description. Do you know what I did wrong ?
I'm on the domoticz
Version: 3.6046
Build Hash: 0140857-modified
Axis is for Mbp/s and ms. Its a description of the value and you can fill in what you like.
The values needs the be the same so that is not correct.
Must be something wrong with your script or the program where you created the script is not correct for it. With some program's you get wrong characters extra in the script and then you get problems while running it.
Try this one and use WinSCP / Putty or Sublime Text for editing. Make sure you give it executable rights and then it must work.
Check also all 3 idx the you create the right one's.
I'm running latest Beta and this script is running fine.
Thank you for your inputs, I have made the script file from the scratch in vi and all is working perfect. First file was made in Notepad++ and never ever before have issue like this.
dtech wrote:Thank you for your inputs, I have made the script file from the scratch in vi and all is working perfect. First file was made in Notepad++ and never ever before have issue like this.