Skip to content
Snippets Groups Projects
Commit 664a39b0 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

fix shellcheck; fix returncode of ssh command

parent 7b4e92ba
No related branches found
No related tags found
1 merge request!40fix shellcheck; fix returncode of ssh command
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
# ah - Axel Hahn <axel.hahn@iml.unibe.ch> # ah - Axel Hahn <axel.hahn@iml.unibe.ch>
# #
# 2021-05-31 ah v1.0 first lines # 2021-05-31 ah v1.0 first lines
# 2022-02-11 ah v1.1 fix shellcheck; fix returncode of ssh command
# ================================================================================ # ================================================================================
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
...@@ -19,33 +20,36 @@ ...@@ -19,33 +20,36 @@
# param string action; one of register|unregrister|status # param string action; one of register|unregrister|status
# param string hostname; given for register and unregister # param string hostname; given for register and unregister
function _runssh(){ function _runssh(){
local _rc=0
sProtocol=`j_getFullTarget "" | cut -f 1 -d ":"` sProtocol=$(j_getFullTarget "" | cut -f 1 -d ":")
if [ ${sProtocol} = "rsync" -o ${sProtocol} = "scp" -o ${sProtocol} = "sftp" ]; then if [ "${sProtocol}" = "rsync" -o "${sProtocol}" = "scp" -o "${sProtocol}" = "sftp" ]; then
sSshTarget=`j_getFullTarget "" | cut -f 3 -d "/"` sSshTarget=$(j_getFullTarget "" | cut -f 3 -d "/")
if [ ! -z $sSshTarget ]; then if [ -n "$sSshTarget" ]; then
sSshParams= sSshParams=
sFileSshPrivkey=`_j_getvar ${STORAGEFILE} "ssh-privatekey"` sFileSshPrivkey=$(_j_getvar ${STORAGEFILE} "ssh-privatekey")
if [ ! -z $sFileSshPrivkey ]; then if [ -n "$sFileSshPrivkey" ]; then
sSshParams="${sSshParams} -i ${sFileSshPrivkey}" sSshParams="${sSshParams} -i ${sFileSshPrivkey}"
fi fi
sSshCmd=`_j_getvar ${STORAGEFILE} "storage-registercmd"` sSshCmd=$(_j_getvar "${STORAGEFILE}" "storage-registercmd")
if [ -z "$sSshCmd" ]; then if [ -z "$sSshCmd" ]; then
echo "WARNING: Missing storage-registercmd = ... in ${STORAGEFILE} for a command to execute via SSH." echo "WARNING: Missing storage-registercmd = ... in ${STORAGEFILE} for a command to execute via SSH."
_rc=1
else else
echo ssh ${sSshParams} ${sSshTarget} ${sSshCmd} $* echo "ssh ${sSshParams} ${sSshTarget} ${sSshCmd} $*"
color cmd color cmd
ssh ${sSshParams} ${sSshTarget} ${sSshCmd} $* ssh ${sSshParams} ${sSshTarget} ${sSshCmd} $*
_rc=$?
color reset color reset
fi fi
fi fi
else else
echo INFO: storage protocol is $sProtocol - skipping register via ssh. echo "INFO: storage protocol is $sProtocol - skipping register via ssh."
fi fi
return $_rc
} }
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment