LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 03-22-2011, 06:47 AM   #16
vanid
LQ Newbie
 
Registered: Mar 2011
Posts: 11

Rep: Reputation: 0

HI

I too in need of the above code for telnet. here I not understood how set up a prompt:

i.e here in target.txt i hav enot uderstoo what they mean
route-server.cerf.net
route-server.ip.tiscali.net

for telnet to invoke...we need login name and password...where they are here

please anyone do clarify my doubt....and thanks
 
Old 04-27-2012, 08:16 AM   #17
ThemHuyen
LQ Newbie
 
Registered: Apr 2012
Posts: 1

Rep: Reputation: Disabled
The error was due to the fact that Cisco router/switch doesn't not accept any command that is not Cisco's such "found prompt, sending command:..." and also Mathewg42's suggested code seems to have a missing the EOF to ensure the script is not terminated too early. Below is my suggested script, it is for ssh (tested and worked fine with Solaris). However, you can modify it to support telnet session (just take extra care with the prompt as telnet may ask for the userid and password more than once).

(solaris)$ cat test.exp

#!/usr/local/bin/expect
#Written by ThemHuyen. Date 27/04/2012
#
#
#
set timeout 20
set pwd "your_passwd_goes_here"
set file [open target.txt r]
set ip_list [split [read $file] "\n"]
close $file
foreach host $ip_list {
if {$host != ""} {
spawn ssh -o StrictHostKeyChecking=no $host
expect {
"ssword:" { send "$pwd\r" }
}
set load_cmd [open "commands.txt" r]
set cmd_list [split [read $load_cmd] "\n"]
close $load_cmd
expect {
{#} { foreach command $cmd_list {
if {$command != ""} {
send "$command\n"
}
}
}
}
expect EOF
}
}

########################

(solaris)$ cat commands.txt
show ip int brief
show int sum
show clock
exit

########################

(solaris)$ cat target.txt
10.10.10.10
11.11.11.11
12.12.12.12
13.13.13.13

########################
 
Old 05-17-2012, 11:51 PM   #18
jayaramprasad
LQ Newbie
 
Registered: Sep 2011
Posts: 8

Rep: Reputation: Disabled
Hi,

I have a requirement like below

I have a bash script by executing it it will ask the few inputs like IPaddress, hostname,
path to install the application etc...

so i wanted to automate this using expect without modifying that script

How can i pass the inputs from another script using expect to the main script.
 
  


Reply

Tags
bash, expect, script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
expect/bash sk8guitar Programming 5 10-06-2009 12:00 PM
Trouble calling 'expect' from bash raypen Linux - Software 1 06-01-2006 08:05 PM
expect scripts and cron banderson Linux - Software 8 05-27-2005 04:44 AM
using expect scripts for remote admin jmr71769 Linux - General 3 01-21-2004 01:27 PM
Bash scripts? BajaNick Programming 3 07-05-2003 10:13 PM


All times are GMT -5. The time now is 06:35 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration