Added list option field to be passed to scp
Usage of echoerr for error messages
This commit is contained in:
21
seqs/ssh.sh
21
seqs/ssh.sh
@@ -32,7 +32,7 @@ step_5() {
|
|||||||
local sshPort=22
|
local sshPort=22
|
||||||
|
|
||||||
if [ -z "$2" ] || [ "$2" == "" ] ; then
|
if [ -z "$2" ] || [ "$2" == "" ] ; then
|
||||||
echo " [E] Host not provided."
|
echoerr " [E] Host not provided."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ step_10() {
|
|||||||
# Parse a list to transfer files and/or execute commands on one or different hosts
|
# Parse a list to transfer files and/or execute commands on one or different hosts
|
||||||
#
|
#
|
||||||
# List format
|
# List format
|
||||||
# <COMMAND h,f,u>|<STRING>|[STRING2]
|
# <COMMAND h,f,u>|<STRING>|[STRING2]|[OPTIONS]
|
||||||
# COMMAND h|H|host - Change user@host:port for the following ssh/scp commands
|
# COMMAND h|H|host - Change user@host:port for the following ssh/scp commands
|
||||||
# f|F|file - Source- and destination file path combination
|
# f|F|file - Source- and destination file path combination
|
||||||
# u|U|update - Execute command on the remote host
|
# u|U|update - Execute command on the remote host
|
||||||
@@ -77,15 +77,19 @@ step_10() {
|
|||||||
# STRING2 h - port
|
# STRING2 h - port
|
||||||
# f - destination file path
|
# f - destination file path
|
||||||
# u - not used
|
# u - not used
|
||||||
|
#
|
||||||
|
# OPTIONS h - not used
|
||||||
|
# f - Options passed to scp
|
||||||
|
# u - not used
|
||||||
#
|
#
|
||||||
parseList() {
|
parseList() {
|
||||||
local errorMsg=""
|
local errorMsg=""
|
||||||
|
|
||||||
if [ -z "$1" ] || [ ! -f "$1" ]; then
|
if [ -z "$1" ] || [ ! -f "$1" ]; then
|
||||||
if [ -z "$1" ] || [ "$1" == "" ] ; then
|
if [ -z "$1" ] || [ "$1" == "" ] ; then
|
||||||
echo " [E] No Command list found"
|
echoerr " [E] No Command list found"
|
||||||
else
|
else
|
||||||
echo " [E] Command list not found: $1"
|
echoerr " [E] Command list not found: $1"
|
||||||
fi
|
fi
|
||||||
if [ ! -z "$1" ] && [ $DRY == 0 ] && [ $QUIET == 0 ] ; then
|
if [ ! -z "$1" ] && [ $DRY == 0 ] && [ $QUIET == 0 ] ; then
|
||||||
read -p " Create template there y/[n]? " answer
|
read -p " Create template there y/[n]? " answer
|
||||||
@@ -104,7 +108,7 @@ parseList() {
|
|||||||
local line=1
|
local line=1
|
||||||
# Working loop without ssh "stealing standard input" by
|
# Working loop without ssh "stealing standard input" by
|
||||||
# https://unix.stackexchange.com/questions/24260/reading-lines-from-a-file-with-bash-for-vs-while
|
# https://unix.stackexchange.com/questions/24260/reading-lines-from-a-file-with-bash-for-vs-while
|
||||||
while IFS='|' read -r lcmd lsrc ldst <&3; do
|
while IFS='|' read -r lcmd lsrc ldst lopt<&3; do
|
||||||
case "$lcmd" in
|
case "$lcmd" in
|
||||||
h|H|host)
|
h|H|host)
|
||||||
if [ -z "$lsrc" ] || [ "$lsrc" == "" ]; then
|
if [ -z "$lsrc" ] || [ "$lsrc" == "" ]; then
|
||||||
@@ -129,7 +133,7 @@ parseList() {
|
|||||||
errorMsg="No host found"
|
errorMsg="No host found"
|
||||||
saveReturn 1
|
saveReturn 1
|
||||||
else
|
else
|
||||||
exe scp -p $aPort $lsrc ${aHost}:$ldst
|
exe scp $lopt -P $aPort $lsrc ${aHost}:$ldst
|
||||||
saveReturn $?
|
saveReturn $?
|
||||||
errorMsg="scp to $aHost failed with $?"
|
errorMsg="scp to $aHost failed with $?"
|
||||||
fi
|
fi
|
||||||
@@ -152,7 +156,7 @@ parseList() {
|
|||||||
esac
|
esac
|
||||||
getReturn
|
getReturn
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo -e " [E] $line:$errorMsg"
|
echoerr -e " [E] $line:$errorMsg"
|
||||||
if [ $QUIET -eq 0 ] ; then
|
if [ $QUIET -eq 0 ] ; then
|
||||||
endReturn -f "Stop on first error"
|
endReturn -f "Stop on first error"
|
||||||
fi
|
fi
|
||||||
@@ -169,7 +173,8 @@ f|/sourcedir/sourcefile|/destdir/destfile
|
|||||||
# host and port are changed for the following lines
|
# host and port are changed for the following lines
|
||||||
h|user@host2|port2
|
h|user@host2|port2
|
||||||
f|/sourcedir/sourcefile|/destdir/destfile
|
f|/sourcedir/sourcefile|/destdir/destfile
|
||||||
f|/sourcedir/sourcefile|/destdir/destfile
|
# copy source recursively
|
||||||
|
f|/sourcedir/sourcefile/dir|/destdir/destfile|-r
|
||||||
u|/destdir/updatescript.sh
|
u|/destdir/updatescript.sh
|
||||||
# host is changed and port set to default 22 for the following lines
|
# host is changed and port set to default 22 for the following lines
|
||||||
h|user@host
|
h|user@host
|
||||||
|
Reference in New Issue
Block a user