How to use `expect` tool to switch users?

Solution Verified - Updated -

Issue

  • 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
Password: 
[root@localhost ~]# 
  • It's required to have some tool/script to work as follows.
[user@localhost ~]$ su - root <someoption> password
[root@localhost ~]#

or

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

Environment

  • 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
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.