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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pass password to "su account" in script?
# 1  
Old 05-21-2014
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:
Code:
$ echo "${password}" | su ${test_account} -c "check_account.sh"
standard in must be a tty

Thank you.

- j

Last edited by vbe; 05-21-2014 at 12:51 PM.. Reason: code tags
# 2  
Old 05-21-2014
Try with expect
# 3  
Old 05-21-2014
Could you set up sudo rules to allow this. There is a NOPASSWD option you can add to them and you command would become:-
Code:
sudo su - ${test_account} -c "check_accounts.sh"


Does this help?



Robin
This User Gave Thanks to rbatte1 For This Post:
# 4  
Old 05-21-2014
Quote:
Originally Posted by hce
I've got following error:

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

Thank you.

- j
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.
These 2 Users Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Can someone please show me a very simple "expect" script to change password in Solaris please?

Ladies & Gents, Can one of you gurus please show me a very simple "expect" script to change the password in Solaris in a script, please? Nothing fancy, no error checking, no nothing. Just to change the password of a new user, it's all. Many thanks in advance. U guys have honestly earned my... (1 Reply)
Discussion started by: Hiroshi
1 Replies

3. Shell Programming and Scripting

How to use 'expect' to pass UID & Password to a "for loop" in shell script?

Friends, Need someone's help in helping me with the below requirement for a script: > For a list of servers(over 100+), I need to login into each of them(cannot configure password-less ssh) & grab few configuration details < I know, this is possible through expect programming in a simple... (14 Replies)
Discussion started by: thisissouvik
14 Replies

4. AIX

How to use 'expect' to pass UID & Password to a "for loop" in shell script?

Friends, Need someone's help in helping me with the below requirement for a script: > For a list of servers(over 100+), I need to login into each of them(cannot configure password-less ssh) & grab few configuration details < I know, this is possible through expect programming in a simple... (2 Replies)
Discussion started by: thisissouvik
2 Replies

5. Shell Programming and Scripting

Passing username and password to a script running inside "expect" script

Hi I'm trying to run a script " abc.sh" which triggers "use.sh" . abc.sh is nothing but a "expect" script which provides username and password automatically to the use.sh script. Please find below the scripts: #abc.sh #!/usr/bin/expect -f exec /root/use.sh expect "*name*" send... (1 Reply)
Discussion started by: baddykam
1 Replies

6. Shell Programming and Scripting

Need to pass parameters to an "at" script...

but the man page seems to not have that feature. Am I missing something? This works: $ foo.sh bar abcThis doesn't: $ at now -f foo.sh bar abcTIA, Ron (2 Replies)
Discussion started by: RonJohn
2 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

script that can give login password for "ssh" without involving STDIN

Hi Folks, I am writing a shell script that can logon to remote machine automatically. But, I am facing one problem. I am using "ssh" command in script and while login into remote machine it asks for passowrd and it stops for STDIN input for password. I want my script to supply password... (2 Replies)
Discussion started by: gydave
2 Replies

9. UNIX for Dummies Questions & Answers

vi -x <filename>.x "script to decrypt w/out asking password"

I'm a newbee in unix. Could anyone help me how to decrypt this using a script w/out asking me for a key. I want the key to be included in the script so everytime I will run the script it will automatically open without aksing me to insert the key. vi -x <myfile>.x (0 Replies)
Discussion started by: Boyet
0 Replies

10. UNIX for Advanced & Expert Users

pf not working properly even with only "pass in all" and "pass out all" rules

i have two rules in my pf.conf file, "pass in all" and "pass out all" i was having issues with getting pf working to begin with, so i went with starting from nothing and working on up. i have an ultrasparc ultra1 200e, with an added 4-port fast ethernet sbus card, running "3.4 GENERIC#85... (4 Replies)
Discussion started by: xyyz
4 Replies
Login or Register to Ask a Question