Calling Expect Script - Telnet


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calling Expect Script - Telnet
# 1  
Old 08-17-2011
Calling Expect Script - Telnet

Hi All,

I have an Expect script which logs into Cisco switch, performs a show interface command. I want to read a file of ip addresses which will be passed to the expect script.

The script to read the file works, the expect script works on it's own but when i call the 'expect' script from the control script it fails with : : spawn: not found

I've looked at many threads on many forums but unable to work this one out, any help would be appreciated.

Script1: Control Script:
Code:
#!/bin/bash
#!/usr/bin/expect -f
#
#
while read  ipadd
do
echo $ipadd
export ipadd
sh ./list-int $ipadd
done < dev-list

Script2 : Expect
Code:
#!/usr/bin/expect
#!/usr/bin
# Variables #
#set device "10.33.220.12"
set device $1
set user ****
set cmd1 "term len 0"
set cmd2 "show ip int brief"
set logout "exit"
set pass ****
set timeout 100

#TELNET
spawn telnet $device
expect "Username:"
send "$user\n"
expect "Password: "
send "$pass\n"
expect ">"
send "en\n"
expect "Password: "
send "$pass\n"
expect "#"
sleep 2
send "$cmd1\n"
expect "#"
end "$cmd2\n"
expect "#"
send "$logout\n"


Last edited by vbe; 08-17-2011 at 10:50 AM.. Reason: please use code tags for your data and code
# 2  
Old 08-17-2011
Quote:
Script1: Control Script:

#!/bin/bash
#!/usr/bin/expect -f
Please remove the expect line from the control script and it will/should work.
# 3  
Old 08-17-2011
Thanks for quick response dude2cool, have done as suggested but same error i'm afraid.
# 4  
Old 08-17-2011
so when you run it manually giving it an IP argument it works, right?

sh ./list-int 10.x.x.x

where list-int is your expect script.

In your control script, modify #!/bin/bash to #!/bin/bash -x, this should enable tracing. Post the output from the run with trace output. If it is a lot of output, put in a file and attach to your post.
# 5  
Old 08-17-2011
Correct, running with manual IP argument works.
Output from run with trace :
Code:
/Scripts$ ./get-int
+ read ipadd
+ echo 10.33.220.12
10.33.220.12
+ export ipadd
+ sh ./list-int 10.33.220.12
./list-int: 17: spawn: not found
couldn't read file "Username:": no such file or directory
./list-int: 19: send: not found
couldn't read file "Password: ": no such file or directory
./list-int: 21: send: not found
couldn't read file ">": no such file or directory
./list-int: 23: send: not found
couldn't read file "Password: ": no such file or directory
./list-int: 25: send: not found
couldn't read file "#": no such file or directory
./list-int: 28: send: not found
couldn't read file "#": no such file or directory
./list-int: 30: send: not found
couldn't read file "#": no such file or directory
./list-int: 32: send: not found

and repeat for every entry in dev-list file.


Thanks again....

Last edited by Scott; 08-17-2011 at 12:51 PM.. Reason: Code tags
# 6  
Old 08-17-2011
Quote:
./list-int: 17: spawn: not found
What is line number 17 of your expect script? it is failing on that.
# 7  
Old 08-17-2011
Yes, that's the error I posted originally. It's the spawn telnet $device command which works when run with manual IP but fails when called from control script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Password check in bash script calling on expect

password check in bash script calling on expect Background: I have to copy a file from one server, to over 100 servers in a test environment. once the file is copied, it requires to have the permissions on the file changed/verified. These are all linux servers. most of them have the same... (1 Reply)
Discussion started by: 2legit2quit
1 Replies

2. Programming

Calling another expect script inside an expect script

I have an expect script called remote that I want to call from inside my expect script called sudoers.push, here is the code that is causing me issues: set REMOTE "/root/scripts/remote" ... log_user 1 send_user "Executing remote script as $user...\n" send_user "Command to execute is: $REMOTE... (1 Reply)
Discussion started by: brettski
1 Replies

3. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

4. Shell Programming and Scripting

Calling a function which uses expect from a shells script

Hi all, This is the first time i am using expect. I am trying to call a function with in the shell script. The function will shh to a new server and will pass the password using expect and send. I need help in calling the fuction i am getting follaowing errors... here the script ... (8 Replies)
Discussion started by: firestar
8 Replies

5. Shell Programming and Scripting

Calling Shell Script from Expect...

Hi there, I need some help regarding the execution of shell script from expect as the method I am trying is giving me error. I wrote an shell program which takes two arguments to telnet to a device and saves the output in a file. Following is the script.... (0 Replies)
Discussion started by: cyberparanoid
0 Replies

6. Shell Programming and Scripting

ssh is not working while calling through expect shell script

Hi, Please share you experience and way out on below error:--> #!/bin/bash -xv FILE=login.txt + FILE=login.txt CONNECT=sshlogin.exp + CONNECT=sshlogin.exp SERVERNAME=$1 + SERVERNAME=192.168.12.1 MyServer="" + MyServer= MyUser="" + MyUser= MyPassword="" + MyPassword= exec 3<&0 +... (6 Replies)
Discussion started by: manish_1678
6 Replies

7. Shell Programming and Scripting

calling expect script in ksh is failing via cron

I'm calling an expect script via a ksh script in cron and it is failing. The script runs fine if i run it manually. Does anyone know if it is an issue with compatibilty and if there is a way around it? (2 Replies)
Discussion started by: bhatia
2 Replies

8. Shell Programming and Scripting

Telnet Expect script question

Hi all, I have written a small expect script which should spawn a telnet session login and execute some commands. #!/usr/bin/expect -f spawn telnet $env(IP) match_max 100000 expect "login:" send -- "******\n" expect -exact "Password:" send -- "****\n" expect "%" Now I have got... (2 Replies)
Discussion started by: stinkefisch
2 Replies

9. Shell Programming and Scripting

Calling Expect script in Perl...

I call a EXPECT script from my perl script with machine IP and a FIle. The script logins to the machine and exports the value. The values to be exported or stored in a file. I have close to 10 machines and I have created 10 files and pass the corresponding files in command line, Now I could like... (4 Replies)
Discussion started by: ramkriz
4 Replies

10. Shell Programming and Scripting

Calling an Expect script from a Webpage using PHP

I have a webpage that is in HTML and PHP. In PHP I have tried using exec, system, shell_exec and passthru functions to call an Expect Script file (temp.exp). This Expect file spawns a telnet session that uses "expect/send" commands to retrieve information from an environmental unit (not a normal... (0 Replies)
Discussion started by: CCUSmith
0 Replies
Login or Register to Ask a Question