- Platform information: Raspberry 4
- Hardware: CPUArchitecture/RAM/storage 4GB
- OS: what OS is used and which version Openhabian
- Java Runtime Environment: which java platform is used and what version
- openHAB version:
- Issue of the topic: please be detailed explaining your issue
- Please post configurations (if applicable):
- Items configuration related to the issue
- Sitemap configuration related to the issue
- Rules code related to the issue
- Services configuration related to the issue
- If logs where generated please post these here using code fences:
I have made a key-based authorization to another server/Synology NAS with the user openhabian
This script finds the last video file from the Synology Surveillance files and post that video to Telegram, activated on an external trigger.
ssh-keygen
after that copied the key to the server with
ssh-copy-id username@remote_host
The instructions came from This website
And the script that I run works perfect in CLI (Putty)
If I run the script from an openHAB rule it doesn’t work
var String TestNr = executeCommandLine("/home/openhabian/testvideo.sh" , 4000)
logInfo("Script tester", "de ontvangen waarde is " + TestNr)
My error message is
Host key verification failed.
adding a whoami
in the script tells me that not openhabian
is using the script but openhab
Is there a way to login to the CLI as user openhab?
So I can generate a ssh key for openhab.
For anyone interested in the script.
#!/bin/bash
# ############################################# #
# File to retreive a video from synology server #
# ############################################# #
# Set de directory and the selected camera
VIDEODIR='/volume1/surveillance/'
CAMERA='cameraname/'
USER_AT_SERVER='username@server'
# Set the Telegram token
TOKEN="00000000:jdhhddjjjdjjdjdjdjdjdjddj"
# Set the receiver
RECEIVER="123456789"
# Set silent to 'true' if you do not want a notification if video arrives
SILENT='true'
#determine date and what time of day it
DATUM=$(date +%Y%m%d)
HOUR=$(date +%k)
AMPM='AM'
# this is needed because if locale doesn't use AM-PM for times
# from 12 onwards it is PM
if [[ ${HOUR} -gt '11' ]]
then
AMPM='PM'
fi
echo "Dateformat Synology Surveillance: ${DATUM}${AMPM}"
# Built the full path
FULLPATH="${VIDEODIR}${CAMERA}${DATUM}${AMPM}/"
# Do a directory check on the remote server
if ssh ${USER_AT_SERVER} "[ ! -d ${FULLPATH} ]"
then
echo 'The directory for this time frame is not available yet.' >&2
exit 1
fi
# Check if there are videos available
FCOUNT=$(ssh ${USER_AT_SERVER} ls -f ${FULLPATH}*.mp4 | wc -l)
echo ${FCOUNT}
if [[ ${FCOUNT} -eq 0 ]]
then
echo 'There is no video available at this moment.' >&2
exit 1
else
echo "There are ${FCOUNT} video(s) in this directory."
echo "Will only show the last one."
fi
# Get the filename of the last video
FILENAME=$(ssh ${USER_AT_SERVER} ls ${FULLPATH} | tail -1)
if [[ ${?} -ne 0 ]]
then
echo "Something went wrong" >&2
exit 1
else
echo "${FILENAME}"
fi
SNAPVIDEO="/var/tmp/${FILENAME}"
#copy the video to a local folder
scp ${USER_AT_SERVER}:${FULLPATH}${FILENAME} ${SNAPVIDEO}
# next we must add script to send to telegram
# Send Telegram message with video
curl -s -X POST "https://api.telegram.org/bot${TOKEN}/sendMediaGroup" -F chat_id="${RECEIVER}" -F media='[{"type":"video","media":"attach://video_1","caption":"Video"}]' -F video_1="@$SNAPVIDEO" -F disable_notification="${SILENT}"
# Remove video from /var/tmp
rm $SNAPVIDEO
exit 0