akai
akai

Reputation: 2052

cat in multiple ssh commands does not work

This is probably very basic but unfortunately I have no idea how to google it.

Why doesn't the snippet below work as expected? I mean, how can I make cat point to the remote file?

#!/bin/bash

ssh user@remoteaddress << EOF
  mkdir sandpit
  cd sandpit
  echo "foo" > foo.txt
  echo `cat foo.txt` > foo2.txt
EOF

Upvotes: 0

Views: 469

Answers (1)

anubhava
anubhava

Reputation: 785296

Use it as:

ssh -t -t user@remoteaddress<<'EOF'
mkdir sandpit
cd sandpit
echo "foo" > foo.txt
cat foo.txt > foo2.txt
xargs kill < pid.txt
exit
EOF

Without quotes around starting EOF all words are subject to shell expansion and reverse quotes are expanded in your current shell not on ssh.

Upvotes: 3

Related Questions