bash: use outside variables when reading multiple lines into ssh

The way you're escaping the here-doc word is preventing variable substitution. Contrast

cat <<\END
$PATH
$LOGNAME
END

versus

cat <<END
$PATH
$LOGNAME
END

update

On closer inspection, I see you're setting a variable in the heredoc. That should not be expanded on the local machine, so you need to escape those in the mysqldump command. Try this:

ssh "$serveruser"@"$serverip" <<EOF
mkdir -p "$serverpath/mysqldumps/"
cd "$serverpath/mysqldumps/"
domainname=somedomain.com
mysqldump -h 192.168.1.4 -udba -ppassword -c --add-drop-table --add-locks --create-options --databases --quick --lock-tables \$domainname > \$domainname.sql
EOF

Tags:

Mysql

Bash