How to pass password to "su account" in script?

Hi,

I need to run a test script to check all test accounts, is it possible to pass the password to su in following command? I've got following error:

$ echo "${password}" | su ${test_account} -c "check_account.sh"
standard in must be a tty

Thank you.

  • j

Try with expect

Could you set up sudo rules to allow this. There is a NOPASSWD option you can add to them and you command would become:-

sudo su - ${test_account} -c "check_accounts.sh"

Does this help?

Robin

1 Like

The reason it does this is because it's designed to not allow exactly what you are trying to do -- because it's an extremely bad idea. It's almost impossible to keep stored plaintext passwords safe.

2 Likes