The following code should work for you:
cat <<EOL | ssh $1@$2 'cat > /etc/kafka/kafka_2.11-0.9.0.0/config/test.sh'
broker.id=$3
listeners=$4
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/tmp/kafka-logs
num.partitions=1
num.recovery.threads.per.data.dir=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
log.cleaner.enable=false
zookeeper.connection.timeout.ms=6000
delete.topic.enable=true
ssl.client.auth=required
security.inter.broker.protocol=SSL
EOL
The first cat
command takes its input from the here document (provided by the shell which expands the positional parameters, $3
and $4
) and its output is piped into the ssh
command.
The cat > /etc/kafka/kafka_2.11-0.9.0.0/config/test.sh
command is single-quoted as it should all be parsed as a single argument for the ssh
command. If it’s not quoted, only the cat
command by itself would be passed to the ssh
command and the shell would parse the >
as an instruction to redirect the output of the ssh
command to a local file. This cat
command runs on the remote server and gets its input from the ssh
connection (if a filename isn’t specified as an operand for a cat
command, it uses standard input instead).
The above command is actually a useless use of cat but I thought it might be easier for a shell-scripting newcomer to follow. You can actually shorten the first line by redirecting input for the ssh
command directly from the here document:
ssh $1@$2 'cat > /etc/kafka/kafka_2.11-0.9.0.0/config/test.sh' <<EOL
This will work for Bash and other POSIX (standards-compliant) shells.