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
|
||||
|
||||
if [ -z "$2" ] || [ "$2" == "" ] ; then
|
||||
echo " [E] Host not provided."
|
||||
echoerr " [E] Host not provided."
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -65,7 +65,7 @@ step_10() {
|
||||
# Parse a list to transfer files and/or execute commands on one or different hosts
|
||||
#
|
||||
# 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
|
||||
# f|F|file - Source- and destination file path combination
|
||||
# u|U|update - Execute command on the remote host
|
||||
@@ -78,14 +78,18 @@ step_10() {
|
||||
# f - destination file path
|
||||
# u - not used
|
||||
#
|
||||
# OPTIONS h - not used
|
||||
# f - Options passed to scp
|
||||
# u - not used
|
||||
#
|
||||
parseList() {
|
||||
local errorMsg=""
|
||||
|
||||
if [ -z "$1" ] || [ ! -f "$1" ]; then
|
||||
if [ -z "$1" ] || [ "$1" == "" ] ; then
|
||||
echo " [E] No Command list found"
|
||||
echoerr " [E] No Command list found"
|
||||
else
|
||||
echo " [E] Command list not found: $1"
|
||||
echoerr " [E] Command list not found: $1"
|
||||
fi
|
||||
if [ ! -z "$1" ] && [ $DRY == 0 ] && [ $QUIET == 0 ] ; then
|
||||
read -p " Create template there y/[n]? " answer
|
||||
@@ -104,7 +108,7 @@ parseList() {
|
||||
local line=1
|
||||
# Working loop without ssh "stealing standard input" by
|
||||
# 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
|
||||
h|H|host)
|
||||
if [ -z "$lsrc" ] || [ "$lsrc" == "" ]; then
|
||||
@@ -129,7 +133,7 @@ parseList() {
|
||||
errorMsg="No host found"
|
||||
saveReturn 1
|
||||
else
|
||||
exe scp -p $aPort $lsrc ${aHost}:$ldst
|
||||
exe scp $lopt -P $aPort $lsrc ${aHost}:$ldst
|
||||
saveReturn $?
|
||||
errorMsg="scp to $aHost failed with $?"
|
||||
fi
|
||||
@@ -152,7 +156,7 @@ parseList() {
|
||||
esac
|
||||
getReturn
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo -e " [E] $line:$errorMsg"
|
||||
echoerr -e " [E] $line:$errorMsg"
|
||||
if [ $QUIET -eq 0 ] ; then
|
||||
endReturn -f "Stop on first error"
|
||||
fi
|
||||
@@ -169,7 +173,8 @@ f|/sourcedir/sourcefile|/destdir/destfile
|
||||
# host and port are changed for the following lines
|
||||
h|user@host2|port2
|
||||
f|/sourcedir/sourcefile|/destdir/destfile
|
||||
f|/sourcedir/sourcefile|/destdir/destfile
|
||||
# copy source recursively
|
||||
f|/sourcedir/sourcefile/dir|/destdir/destfile|-r
|
||||
u|/destdir/updatescript.sh
|
||||
# host is changed and port set to default 22 for the following lines
|
||||
h|user@host
|
||||
|
Reference in New Issue
Block a user