The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Call a perl script inside a shell script chriss_58 Shell Programming and Scripting 3 12-01-2008 04:28 AM
Using expect script in a shell script or vice versa nua7 Shell Programming and Scripting 0 07-18-2008 08:16 AM
invoking a shell script inside cgi shell script smriti_shridhar Shell Programming and Scripting 2 07-09-2008 02:50 AM
Need help with Expect and Shell script tonan Shell Programming and Scripting 1 04-10-2008 11:45 PM
Using expect script in a shell script Naresh Kumar Shell Programming and Scripting 3 06-10-2006 09:54 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-06-2009
robbiezr robbiezr is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 12
Unhappy how to run shell script inside expect script?

I have the code like this :


Code:
shell script continues ...
....
          expect -c"
          spawn telnet $ip
          expect "login:"
          send \"$usrname\r\"
          expect "Password:"
          send \"$passwd\r\"
          expect "*\>"
          send \"$cmdstr\r\"
          expect "*\>"
          send \"exit\r\"
          expect eof"
....  
shell script continues...

$cmdstr is the command i want to execute on the remote device.
There are several cmds to execute on the remote device,but i have to telnet several times to the device to execute them.
If I can write some shell script inside expect script,then ,it loop to execute each cmd after login in,so it will telnet only once each device to execute all the cmds on it.

Anyone can tell me how to write shell scripts inside expect scripts?
Or,if you get some other methods to telnet only once to execute all cmds.Pls tell me.

Thanks.

Last edited by robbiezr; 05-06-2009 at 08:59 AM..
  #2 (permalink)  
Old 05-06-2009
JerryHone JerryHone is offline
Registered User
  
 

Join Date: Nov 2006
Location: UK
Posts: 178
Can you just store the multiple commands inside an array ...

Code:
set cmdstr(0) "command1"
set cmdstr(1) "command2"
set cmdstr(2) "command3"
expect -c"
spawn telnet $ip
expect "login:"
send \"$usrname\r\"
expect "Password:"
send \"$passwd\r\"
expect "*\>"
for {set i 0} {$i<[array size cmdstr]} {incr i} {
    send "$cmdstr($i)\r"
    expect "*\>"
}
send \"exit\r\"
expect eof"

Closed Thread

Bookmarks

Tags
expect, shell

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0