First of all, most servers are configured by default to NOT allow remote root login via ssh.
Secondly, why not use SSH keyfiles to allow passwordless logins? It is WAY more secure than storing your password.
- Set up an account (for the case of this example, let's call it "automate") that has passwordless sudo access to the automation command (see the NOPASSWD flag on
sudoers
) - Use ssh-keygen to configure passwordless access to this account from the remote system
Instead of using
expect://
to run the command, simply run the command directly:ssh automate@10.1.2.3 sudo theCommand