I'm trying to run a command over SSH like this in a here-document:
ssh example.com <<END sudo /etc/init.d/apache2 reload END
Which normally works except when I'm trying to run something that needs input, such as the password for sudo. In that case, I'm getting the following message:
sudo: no tty present and no askpass program specified
I know I can use the
-t flag on SSH to allocate a pseudo-tty such as this:
ssh -t example.com "sudo /etc/init.d/apache2 reload"
And it'll work, but when I try the same thing with here-document, it doesn't work and I'll get the same error about no tty being present:
ssh -t example.com <<END sudo /etc/init.d/apache2 reload END
Any idea how I can make this work?
Also, in case you are wondering why I want it to work with the here-document instead of just passing it on the same line, it is because the input commands (there can be a few) come from a configuration file read by a script and I've heard it avoids the trouble of escaping the commands for the quotes, double quotes, etc.