问题
I need to ssh into a machine and execute a bunch of commands under sudo bash
. Here is what I've tried:
sshpass -p "vagrant" ssh vagrant@33.33.33.100 "sudo bash -i -c <<EOF
echo
ls
echo
EOF"
But it throws me 'bash: -c: option requires an argument\n'
. How can I fix this?
回答1:
You need to remove -c
from your command line to make it accept heredoc:
sshpass -p "vagrant" ssh vagrant@33.33.33.100 "sudo bash <<EOF
echo
ls
echo
EOF"
Also you may remove -i
(interactive) option too.
bash -c
expects you to provide all commands on command line so this may work too:
sshpass -p "vagrant" ssh vagrant@33.33.33.100 "sudo bash -c 'echo; ls; echo'"
来源:https://stackoverflow.com/questions/27012174/heredoc-for-nested-command-in-bash