How to use `expect` tool to switch users?

Solution Verified - Updated -


  • How to use expect tool to switch users?
  • How can one execute su with password in plain text on the same command line? Is there any way to achieve this using some script?
  • When one executes su - root in terminal, it will show like this:
[user@localhost ~]$ su - root
[root@localhost ~]# 
  • It's required to have some tool/script to work as follows.
[user@localhost ~]$ su - root <someoption> password
[root@localhost ~]#


[user@localhost ~]$ su - root | cmd password
[root@localhost ~]#


  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 6.5

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In