#!/usr/bin/env bash # DESCRIPTION: # get ds18b20 sensor value # # DEPENDENCIES: # - sshpass # # PARAMETERS: # 1: ssh host # 2: ssh port # 3: ssh username # 4: ssh password # 5: ds18b20 node # # FUNCTIONS: # # # VARIABLES: # if [ -z "${1}" ] || \ [ -z "${2}" ] || \ [ -z "${3}" ] || \ [ -z "${4}" ] || \ [ -z "${5}" ]; then printf "%s\n" \ "Usage example: ${0} 'host' 'port' 'username' 'password' 'node'" exit 1 fi if ! command -v sshpass &> /dev/null; then printf "%s\n" "Not found dependencies" exit 1 fi host=${1} port=${2} user=${3} pass=${4} node=${5} # # MAIN: # temp=$(sshpass -p "${pass}" ssh "${user}@${host}" -p "${port}" \ -o "StrictHostKeyChecking=no" \ -o "UserKnownHostsFile=/dev/null" \ -o "LogLevel=ERROR" \ "cat /sys/bus/w1/devices/${node}/temperature" ) if [ "${temp}" -lt 0 ]; then printf "%s\n" "$(("${temp}" / 1000)).$((-1 * "${temp}" % 1000))" else printf "%s\n" "$(("${temp}" / 1000)).$(("${temp}" % 1000))" fi exit 0