![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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.. |
|
||||
|
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"
|
![]() |
| Bookmarks |
| Tags |
| expect, shell |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|