Home>

In the shell, use "su --user" with the except command from one general user to another general user
We are switching users.
After that, I would like to proceed with the subsequent processing with the switched user. Is there any way?
If i exit expect, you will return to the original user.

Command

expect -c "
swapn su --user
expect'Passwd:'
send'pw'
"

Separate processing ← I want to execute this as a user.


Background and situation

I created a wrapper shell because I want the product PGM (shell) to be judged as an error.
The execution user of the wrapper shell is userA, which is difficult to change.
The product PGM must be run as userB.
I think there is a way to execute userB with sudo, but it is difficult to change the OS settings.

  • Answer # 1

    If you exit expect, you will return to the original user.

    That's right.

    I would like to proceed with the subsequent processing with the switched user, is there a way?

    expectProceed with the process in.interact interactSubcommands.

    There seems to be a better solution if you write "what you want to do in the first place".