Have a sudo statement inside of a here document. It prompts me for a password, but doesnt wait for me to enter my password. Is there a way I can use the command without sudo or anyway that I can enter the password correctly?
Eg :
while read remotehost
do
ssh -t $2@$remotehost <<REMOTE
ls /path/to/file/ | while read line
do
sudo vserver \$line enter
echo "\$line Hello world"
done
REMOTE
done < "$remotehostlist"
This asks for password for the following line sudo vserver $line enter. But it doesnt wait for me to enter password. Also if I type something it appears in cleartext.
Is the password request coming from sudo or ssh. It seems like belt and suspenders (overkill). Just ssh from your normal ID to the host and id you want, if possible, passwordless using keys.
Does sudo actuall insist on a terminal explicitly, not implicitly for password? If b, can the sudo options for password from stdin -S or other source -A help ?
use NOPASSWD for sudo rule for batch jobs. don't use a HERE document that way. put the logic in a remote script and execute that remotely. also - add -n to your ssh loop.
I think there are maybe some errors in your script
if you think everything is ok then you can try this
while read remotehost
do
ssh -t $2@$remotehost <<REMOTE
ls /path/to/file/ | while read line
do
sudo -k
sudo vserver \$line enter
echo "\$line Hello world"
done
REMOTE
done < "$remotehostlist"