GrandPa
GrandPa

Reputation: 504

SSH returning value while using EOF

I am using linux bash shell. I want to return value from ssh while using EOF.I am new to this.

result=$(ssh -T -q -o UserKnownHostsFile=/dev/null -o 
StrictHostKeyChecking=no -o ConnectTimeout=60 -o ConnectionAttempts=3 ${host_name} << EOF
 echo "Get details in mysql"
EOF  2>/dev/null)

This gives error saying

unexpected EOF while looking for matching `)'

In my actual usecase i have somany commands to run on remote host and get results. So i will have somany linux commands in between EOF

Upvotes: 3

Views: 757

Answers (1)

Gohu
Gohu

Reputation: 933

The ending delimiter (EOF) must be alone on its line:

result=$(ssh -T -q -o UserKnownHostsFile=/dev/null -o 
StrictHostKeyChecking=no -o ConnectTimeout=60 -o ConnectionAttempts=3 ${host_name} << EOF
 echo "Get details in mysql"
EOF
2>/dev/null)

From man bash:

Here Documents
This type of redirection instructs the shell to read input from the current source until a line containing only delimiter (with no trailing blanks) is seen.

Upvotes: 2

Related Questions