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, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content