scriping expect/send


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting scriping expect/send
# 1  
Old 07-24-2009
scriping expect/send

Trying to script an application's interactive add-user function with expect/send.

So far no information is sent, but the add-user function is called.

Any help appreciated! Many Thanks

Code:
#!/bin/sh
#!/usr/bin/expect -f

#PATH to add-user: PATH to expect
PATH=/opt/app-1/sbin:/usr/bin

#Set Variables

set login "app-adm2"
set password "App-password"

#Add user command
app1-adduser

expect "*?ogin :*"
send -- "$login\r"

expect "*?ogin password :*"
send -- "$password\r"

expect "*?ogin password (again) :*"
send -- "$password\r"

expect eof

# 2  
Old 07-24-2009
I think you might want to use:

Code:
spawn app1-adduser

Also, have a look at autoexpect to generate some code based on a real interactive session.
# 3  
Old 07-24-2009
autoexpect

Thanks Peterro!

Autoexpect worked like a charm!

$autoexpect -p ./app1-adduser

(note: I used -p flag b/c some text from app1-useradd broke the script when it read directly from interactive session. -p flag looks for the prompt. man autoexpect has info.)

Here is the code it generated:

Code:
set timeout -1

spawn ./app1-adduser

match_max 100000

expect -exact "Login : "
send -- "app-adm\r"

expect -exact "Login password : "
send -- "App-password\r"

expect -exact "Login password (again) : "
send -- "App-password\r"

expect eof

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

How to use expect and send command in UNIX/Linux?

Hello Everyone, I am executing a unix script which logs into 50+ servers (netapp servers) and runs some commands and captures output locally. Below is the code snippet. file1.txt has names of all the remote servers where I am logging in. #!/bin/ksh #!/usr/bin/expect touch... (1 Reply)
Discussion started by: rahul2662
1 Replies

3. Shell Programming and Scripting

Expect/Send

Hello Team, Am trying to write a script for installing PAM in mulitiple server by using expect and send command. Am facing the below issues,could you please assist. thanks. # cat /tmp/gkscrpt.exp #!/usr/bin/expect -d spawn /tmp/agent/install_pam.sh expect -re "(y/n) " send --... (1 Reply)
Discussion started by: gowthamakanthan
1 Replies

4. AIX

Send ctrl+C in expect script

Hi, Am trying to transfer file via FTP using expect script from server to client i need to interrupt the file transfer between server and client Please help what should used in expect code.. I used send "ctrl+c\r" expect "Aborted" but that didnt work.. I need what should... (3 Replies)
Discussion started by: Priya Amaresh
3 Replies

5. Shell Programming and Scripting

Command substitution in send/expect. Please help!

Hi, the following code is not working. How can I cat the last modified file in the path /asdf. Please help! expect "asdf%" {send "cat `ls -rt /asdf|tail -1` \r"} (2 Replies)
Discussion started by: thulasidharan2k
2 Replies

6. Shell Programming and Scripting

within shell script send expect and if else

Hi, I have written one shell script , using that i am able to connect to remote machine but i have to #!/usr/bin/expect -f set address set username set password set OOLpath set dbusername set dbpasswd set tnsname set recdbusername set recdbpasswd set rectnsname spawn ssh... (2 Replies)
Discussion started by: mnmonu
2 Replies

7. Shell Programming and Scripting

within shell script send expect and if else

Hi I have written one shell script , using that i am able to connect to remote machine but i have to #!/usr/bin/expect -f set address set username set password set OOLpath set dbusername set dbpasswd set tnsname set recdbusername set recdbpasswd set rectnsname spawn ssh... (1 Reply)
Discussion started by: mnmonu
1 Replies

8. Shell Programming and Scripting

Use Send command of Expect package

HI All, I am currently working on one command line application on AIX (Unix Platform).Here i need to use Expect package. By using Expect package at the top of the script,i want to use just Send command of Expect package to send characters like, 1. Press Enter key 2. Press spacebar 3.... (6 Replies)
Discussion started by: neha123
6 Replies

9. Shell Programming and Scripting

replacing expect/send

Dear all, I have a code which needs to do : spawn ftp 10.4.12.22 expect "Name (10.4.12.22:mmsadmin):" send "BillingUser\r" expect "Password:" send "BillingUser\r" expect "ftp>" send "bye" but when i run its say spawn, send and expect is not found... how can i enable or install... (1 Reply)
Discussion started by: asadlone
1 Replies

10. Shell Programming and Scripting

Expect Send

Dear All, I wanna write a script in which it expect something and if it gets whats expected then send the command relating to that. for instance Userame: Asad Required Password for Asad: ****** I tried to use the expect key word but its does not work. I am using Solaris 8/9 If... (1 Reply)
Discussion started by: asadlone
1 Replies
Login or Register to Ask a Question