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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing username and password to a script running inside "expect" script
# 1  
Old 08-23-2012
Data 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

Code:
#!/usr/bin/expect -f
exec /root/use.sh
expect "*name*"
send "baddy\r"
expect "*word*"
send "compaq\r"
expect eof

my second script use.sh is placed in /root/ directory..
please find the script below:

Code:
#!/bin/sh
echo "Username: "
read u
echo "Password: "
read p
echo "$u --- $p"

When I execute the script abc.sh I get just

Username:

Unless and until I entert it manually it won't proceed ahead. I understand that since now the control is in use.sh , expect is not working. So any workaround for this..??? Please help me out.

Please note that this is just a 4-5 lines script similar to some other script we use in our project. I cannot change anything in "use.sh". I'm free to edit abc.sh.

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.

Last edited by Corona688; 08-23-2012 at 02:48 PM..
# 2  
Old 08-23-2012
replace exec /root/use.sh with spawn /root/use.sh
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

Expect: spawn id exp5 not open while executing "expect "$" { send "sudo su -\r" }"

Hi All, i am trying to ssh to a remote machine and execute certain command to remote machine through script. i am able to ssh but after its getting hung at the promt and after pressing ctrl +d i am gettin the out put as expect: spawn id exp5 not open while executing "expect "$" {... (3 Replies)
Discussion started by: Siddharth shivh
3 Replies

3. 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

4. SuSE

SUSE "passwd username" ask for password 4 times

Below is the error I'm getting. # passwd username Changing password for username. New Password: Reenter New Password: Password changed. New UNIX password: Retype new UNIX password: Password has been already used. Choose another. passwd: Authentication token manipulation error# cat... (0 Replies)
Discussion started by: toor13
0 Replies

5. 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

6. 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

7. Shell Programming and Scripting

Expect Script - Variables are Empty immediately after "Setting" Them?

Hello All, I have embedded some expect code inside a Bash script I'm writing, but for some reason any variable I 'set' to something is showing as empty immediately on the next line... I haven't run into this problem before so I'm not sure what it could be...? I'm guessing it has something to... (4 Replies)
Discussion started by: mrm5102
4 Replies

8. Shell Programming and Scripting

expect script not running in cron "Urgent"

I wrote a script to download the files from sftp location to local. while running the script manually its working fine. when i schedule the same in cron its not working.... :wall::wall: here is the script: #!/bin/bash ... (2 Replies)
Discussion started by: ganga39
2 Replies

9. Shell Programming and Scripting

exec perl in expect script yields "invalid command"

I'm trying to execute something like this: exec perl -i -pe 's/\015/\012/g' '${file}' in my expect script and I get: error "invalid command name \"perl\". however, if I run perl -i -pe 's/\015/\012/g' "/Users/Shared/menu-items.txt" directly in my terminal, it runs fine. I'm an... (4 Replies)
Discussion started by: dpouliot
4 Replies

10. HP-UX

script running with "ksh" dumping core but not with "sh"

Hi, I have small script written in korn shell. When it is called from different script, its dumping core, but no core dump when we run it standalone. And its not dumping core if we run the script using "/bin/sh" instead of "ksh" Can some body please help me how to resolve this issue. ... (9 Replies)
Discussion started by: simhe02
9 Replies
Login or Register to Ask a Question