2016-02-28 40 views
0

这可能是非常基本的,但不幸的是我不知道如何谷歌它。猫在多个ssh命令不起作用

为什么下面的代码段不按预期工作?我的意思是,我怎样才能让cat指向远程文件?

#!/bin/bash 

ssh [email protected] << EOF 
    mkdir sandpit 
    cd sandpit 
    echo "foo" > foo.txt 
    echo `cat foo.txt` > foo2.txt 
EOF 

回答

3

使用它作为:

ssh -t -t [email protected]<<'EOF' 
mkdir sandpit 
cd sandpit 
echo "foo" > foo.txt 
cat foo.txt > foo2.txt 
xargs kill < pid.txt 
exit 
EOF 

没有引号开始EOF所有的话都受到shell扩展和反向行情在当前shell不是SSH展开。

+0

谢谢,这个工程。那么,我真正想要做的就是'杀死''cat pid.txt \''。在这种情况下我应该怎么做? – akai

+0

你可以做'xargs kill anubhava

+1

现在我已经检查了编辑,一切都解决了。非常感谢你。 – akai