For QNAP user there is much to do before this script working well… I’ve done the job.
QNAP User don’t have full command on console. Massiv of things are missing. They use busybox and this is rudimentary.
They need a boost and this is:
https://github.com/Entware-ng/Entware-ng/wiki/Install-on-QNAP-NAS
Old Optware is not woring, 'cause no support is given yet and security fails. After install of Entware you can install all needed tools.
Use:
opkg update
opkg install nano mc smartctl grep
Grep is totally less one without all functions grep really have!
Next important thing is crontab! You must do a special procedure that crontab works well:
https://wiki.qnap.com/wiki/Add_items_to_crontab
I save my script via /opt/bin/syspi.sh
This is my code:
#!/bin/sh ip="yourip:8080" user="user" password="password" UPTIME1=$(/mnt/ext/usr/bin/uptime | /opt/bin/grep -ohe 'load average[s:][: ].*' | /bin/awk '{ print $4+0 }') TEMP1=$(/opt/bin/smartctl -d sat -A /dev/sda | grep -i Temperature_Celsius | /bin/tr -s ' ' | /bin/cut -d\ -f 10) TEMP2=$(/opt/bin/smartctl -d sat -A /dev/sdb | grep -i Temperature_Celsius | /bin/tr -s ' ' | /bin/cut -d\ -f 10) DISKUSAGE=$(df | grep md0 | awk '{ print $5+0 }') USEDRAM=$(free | grep Total | awk '{print $3/1000}') curl -s --user $user:$password -X PATCH "http://$ip/api/variables/CPULoadNAS?type=value&valueOrExpression=$UPTIME1" curl -s --user $user:$password -X PATCH "http://$ip/api/variables/DiskTemp1NAS?type=value&valueOrExpression=$TEMP1" curl -s --user $user:$password -X PATCH "http://$ip/api/variables/DiskTemp2NAS?type=value&valueOrExpression=$TEMP2" curl -s --user $user:$password -X PATCH "http://$ip/api/variables/DiskUsageNAS?type=value&valueOrExpression=$DISKUSAGE" curl -s --user $user:$password -X PATCH "http://$ip/api/variables/UsedRamNAS?type=value&valueOrExpression=$USEDRAM"
Create a variable device and all needed variables at pimatic:
{ "variables": [ { "name": "CPULoadNAS", "expression": "$CPULoadNAS", "type": "number", "unit": "%", "acronym": "CPU", "label": "CPULoad" }, { "name": "DiskTemp1NAS", "expression": "$DiskTemp1NAS", "type": "number", "unit": "°C", "label": "DiskTemp1", "acronym": "t" }, { "name": "DiskTemp2NAS", "expression": "$DiskTemp2NAS", "type": "number", "unit": "°C", "label": "DiskTemp2", "acronym": "t" }, { "name": "DiskUsageNAS", "expression": "$DiskUsageNAS", "type": "number", "unit": "%", "label": "DiskUsage", "acronym": "du" }, { "name": "UsedRamNAS", "expression": "$UsedRamNAS", "type": "number", "unit": "MB", "label": "RAM", "acronym": "ram" } ], "xAttributeOptions": [], "id": "qnapnas", "name": "QNAPNAS", "class": "VariablesDevice" }
Variables:
{ "name": "CPULoadNAS", "value": 7.47 }, { "name": "DiskTemp1NAS", "value": 38 }, { "name": "DiskTemp2NAS", "value": 38 }, { "name": "DiskUsageNAS", "value": 64 }, { "name": "UsedRamNAS", "value": 401.256 }
It’s look like:
Thanks to @Stokstaart for init this thread.