I’ve never used expect before but need a script to do the following for a large list of hosts
- ssh into a machine
- su to root and enter the root password
- sed a file in /etc/passwd to replace some text with some other text, for this example lets just say the original text is TEXT and the text to replace it with is NEWTEXT
Can anyone help?
Understandably, executing a script to process commands as root is a huge security issue, and is generally not allowed.
However, Expect has the ability to run a pseudo terminal, so it can act just like a human typing away at a keyboard.
This is more or less what you asked, but is untested.
If it were me, I’d change the sed command to something far less destructive, like
grep TEXT /etc/passwduntil confident it works well. For a remote command which display output you want to see, use