Reputation: 41
I have been trying to make a looping work while accessing via SSH Remote command but it doesn't work. The command works when ran directly in host.
scp file root@${SERVER}:/tmp
ssh ${SERVER} "
while IFS= read -r line; do
echo "$line"
done </tmp/file
"
I have tried using the single quotes in main script but it causing errors.
bash: line n: warning: here-document at line n delimited by end-of-file
Any advise will be much appreciated.
UPDATE
testfile
1
2
3
4
5
6
Script test
SERVER='client'
ssh ${SERVER} '
echo "inside remote ClientServer"
echo "cat testfile"
cat /tmp/testfile
while read line; do
echo "${line}"
done <</tmp/testfile
'
echo "Back to MasterServer..."
Terminal Result
root@server]# ./test
S
Kernel 4.14.35-1902.10.7.el7uek.x86_64 on an x86_64
inside remote ClientServer
cat testfile
1
2
3
4
5
6
bash: line 8: warning: here-document at line 8 delimited by end-of-file (wanted `/tmp/testfile')
Back to MasterServer...
Thank you.
Upvotes: 0
Views: 609
Reputation: 2610
You will probably want to use single quotes to pass the remote commands verbatim:
scp file root@${SERVER}:/tmp
ssh ${SERVER} '
while IFS= read -r line; do
echo "$line"
done </tmp/file
'
Ensure you're using </tmp/file
, not <</tmp/file
. The sequence <<
is used to start a here-document which is not what you want in this case.
Upvotes: 1