Page 1 of 1

Domoticz version from .bashrc

Posted: Wednesday 31 January 2018 23:42
by htilburgs
I'm using the following command to determine the version of Domoticz in my /home/pi/.bashrc script:

Code: Select all

curl -s -X GET "http://127.0.0.1:8088/json.htm?type=command&param=getversion" | /bin/grep "version :" | awk {'print $3'} | /usr/bin/cut -d '"' -f 2 | /usr/bin/cut -d '"' -f 1
The result is:

Code: Select all

2.4.1
3.8872
The reason is there is twice the word version

Code: Select all

{
   "DomoticzUpdateURL" : "http://www.domoticz.com/download.php?channel=beta&type=release&system=linux&machine=armv7l",
   "HaveUpdate" : false,
   "Revision" : 8872,
   "SystemName" : "linux",
   "build_time" : "2018-01-29 16:59:49",
   "dzvents_version" : "2.4.1",
   "hash" : "fc97f529",
   "status" : "OK",
   "title" : "GetVersion",
   "version" : "3.8872"
}
Now my knowledge stops... How can I solve this, so I see only the Domoticz version, in this case 3.8872 ??

Re: Domoticz version from .bashrc

Posted: Wednesday 31 January 2018 23:48
by Damsee
You can add another grep command to remove the dzvents version.
Add it before your 1sr grep : grep -v dzvents

Hope that helps ;-)

Re: Domoticz version from .bashrc

Posted: Wednesday 31 January 2018 23:59
by htilburgs
Yes! That did the trick. Thnx.

Re: Domoticz version from .bashrc

Posted: Thursday 01 February 2018 0:05
by htilburgs
For who is interested: Edit the file /home/pi/.bashrc and put at the end the following code:

Code: Select all

echo "$(tput setaf 2)
/////    ////    /     /    ////   ///////   /////  //////   //////
/    /  /    /   //   //   /    /     /        |    /            /
/    /  /    /   / / / /   /    /     /        |    /           /
/    /  /    /   /  /  /   /    /     /        |    /          /
/    /  /    /   /     /   /    /     /        |    /         /
/////    ////    /     /    ////      /      /////  //////   //////

`date +"%A, %e %B %Y, %r"`

Hardware Model............: `(tr -d '\0' </proc/device-tree/model)`
OS Version................: `/usr/bin/lsb_release -s -d  | grep Raspbian | awk {'print $1,$3,$4'}`
Kernel....................: `uname -srmo`

Domoticz Version..........: `curl -s -X GET "http://127.0.0.1:8088/json.htm?type=command&param=getversion" | /bin/grep -v dzvents | /bin/grep "version" | awk {'print $3'} | /usr/bin/cut -d '"' -f 2 | /usr/bin/cut -d '"' -f 1`
Domoticz Release..........: `curl -s -X GET "http://127.0.0.1:8088/json.htm?type=command&param=getversion" |grep -Po '(?<=channel=)[^&]*'`
Domoticz Servicebuild.....: `curl -s -X GET "http://127.0.0.1:8088/json.htm?type=command&param=getversion" | /bin/grep "build_time" | awk {'print $3,$4'} | /usr/bin/cut -d '"' -f 2 | /usr/bin/cut -d '"' -f 1`
$(tput setaf 1)
Uptime....................:  `exec --  uptime -p`
Memory....................:  `cat /proc/meminfo | grep MemFree | awk {'print $2'}`kB (Free) / `cat /proc/meminfo | grep MemTotal | awk {'print $2'}`kB (Total)
Running Processes.........:  `ps ax | wc -l | tr -d " "`
IP Addresses..............:  `sudo hostname -I`
Free Disk Space SD........:  `df -Pk | grep -E '/root' | awk '{ print $4 }' | awk -F '.' '{ print $1 }'`k on /root
CPU Temperature...........:  `exec -- /opt/vc/bin/vcgencmd measure_temp | cut -c "6-9"` C
$(tput setaf 2)
Domoticz Service status...: `sudo service domoticz status | grep Active | cut -c "11-54"`
"
The result:
Schermafbeelding 2018-02-01 om 00.04.33.png
Schermafbeelding 2018-02-01 om 00.04.33.png (52.08 KiB) Viewed 2102 times

Re: Domoticz version from .bashrc

Posted: Thursday 01 February 2018 0:39
by waaren
Nice overview of your system. If you want to get the version of domoticz even if not active at the moment:

"path to domoticz dir"/domoticz --help | grep Giz | awk {'print $4'}

Re: Domoticz version from .bashrc

Posted: Thursday 01 February 2018 6:57
by Siewert308SW
Or you could do it a bit cleaner with a double grep.
You could grep the entire piece: '"version" :'

So it becomes:
curl -s -X GET "http://127.0.0.1:8080/json.htm?type=com ... getversion" | /bin/grep '"version" :' | awk {'print $3'} | /usr/bin/cut -d '"' -f 2 | /usr/bin/cut -d '"' -f 1

Re: Domoticz version from .bashrc

Posted: Thursday 01 February 2018 8:07
by htilburgs
Siewert308SW wrote: Thursday 01 February 2018 6:57 Or you could do it a bit cleaner with a double grep.
You could grep the entire piece: '"version" :'

So it becomes:
curl -s -X GET "http://127.0.0.1:8080/json.htm?type=com ... getversion" | /bin/grep '"version" :' | awk {'print $3'} | /usr/bin/cut -d '"' -f 2 | /usr/bin/cut -d '"' -f 1
Thnx for this 'cleaner' version. I'm learning by the day.
Implemented, tested and it works...!

Re: Domoticz version from .bashrc

Posted: Sunday 15 April 2018 17:45
by sincze
htilburgs wrote: Thursday 01 February 2018 8:07
Siewert308SW wrote: Thursday 01 February 2018 6:57 Or you could do it a bit cleaner with a double grep.
You could grep the entire piece: '"version" :'

So it becomes:
curl -s -X GET "http://127.0.0.1:8080/json.htm?type=com ... getversion" | /bin/grep '"version" :' | awk {'print $3'} | /usr/bin/cut -d '"' -f 2 | /usr/bin/cut -d '"' -f 1
Thnx for this 'cleaner' version. I'm learning by the day.
Implemented, tested and it works...!

Code: Select all

{
   "DomoticzUpdateURL" : "http://www.domoticz.com/download.php?channel=beta&type=release&system=linux&machine=armv7l",
   "HaveUpdate" : true,
   "Revision" : 9227,
   "SystemName" : "linux",
   "build_time" : "2018-03-30 12:51:25",
   "dzvents_version" : "2.4.1",
   "hash" : "617c5526",
   "python_version" : "3.5.3 (default, Jan 19 2017, 14:11:04) \n[GCC 6.3.0 20170124]",
   "status" : "OK",
   "title" : "GetVersion",
   "version" : "3.9138"
}
Thanks, you just saved my day. :D I use this to make a backup of my domoticz and store the value of the current version in the filename. domoticz-server-v3.9138-15-04-2018-17.43.32.tar