Need help with the expect script | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Need help with the expect script

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-28-2010
arch12 arch12 is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 12 October 2010, 10:33 PM EDT
Posts: 29
Thanks: 2
Thanked 0 Times in 0 Posts
Need help with the expect script


Code:
#!/opt/sfw/bin/expect -f
set user "*****"
set password "******"
set server_list {"ler01", "ler02"}
foreach server $server_list {
spawn ssh $user@$server
match_max 100000
expect -re "password:"
send "$password\r"
expect -re  "$server $user#"
send -- "su - linus\r"
expect  "$server linus >"
send -- "./apclogcheck.sh"
#expect -re "ler01 root#"
#send -- "exit\r"
expect eof
}


O/p i get this

Code:
+ set user root
+ set password 
+ set server_list {}
+ foreach server {
login34.sh[8]: foreach:  not found
+ spawn ssh @
login34.sh[9]: spawn:  not found
+ match_max 100000
login34.sh[10]: match_max:  not found
+ expect -re password:
expect: illegal option -- r
usage: expect [-div] [-c cmds] [[-f] cmdfile] [args]
+ send \r
login34.sh[12]: send:  not found
+ expect -re server root#
expect: illegal option -- r
usage: expect [-div] [-c cmds] [[-f] cmdfile] [args]
+ send -- su - linus\r
login34.sh[14]: send:  not found
+ expect apcnn01 linus>
couldn't read file "ap linus>": no such file or directory
+ send -- ./apclogcheck.sh
login34.sh[16]: send:  not found
+ expect eof
couldn't read file "eof": no such file or directory
login34.sh[20]: syntax error at line 21 : `}' unexpected


Last edited by arch12; 10-01-2010 at 01:44 AM.. Reason: Please use code tags, thank you!
Sponsored Links
    #2  
Old 10-11-2010
arch12 arch12 is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 12 October 2010, 10:33 PM EDT
Posts: 29
Thanks: 2
Thanked 0 Times in 0 Posts
any suggestions please
Sponsored Links
    #3  
Old 10-11-2010
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
 
Join Date: Apr 2009
Last Activity: 25 August 2014, 5:53 PM EDT
Posts: 1,841
Thanks: 7
Thanked 266 Times in 241 Posts
Okay, this is just a hunch. But it looks like all those error messages are thrown by the shell, and not the expect command.

You may want to check a few things -

(a) see if "expect" is actually at "/opt/sfw/bin/expect".
(b) see if "/opt/sfw/bin" is in your PATH
(c) feed your script to the "expect" command
(d) if the shebang is correct, then add executable permission to the script and execute it rather than sourcing it.

tyler_durden
    #4  
Old 10-11-2010
arch12 arch12 is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 12 October 2010, 10:33 PM EDT
Posts: 29
Thanks: 2
Thanked 0 Times in 0 Posts
yep the path is correct the other login script works with that path.
Sponsored Links
    #5  
Old 10-11-2010
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
 
Join Date: Apr 2009
Last Activity: 25 August 2014, 5:53 PM EDT
Posts: 1,841
Thanks: 7
Thanked 266 Times in 241 Posts
Quote:
Originally Posted by arch12 View Post
yep the path is correct the other login script works with that path.
And did you feed your script to the expect command?

tyler_durden
Sponsored Links
    #6  
Old 10-12-2010
arch12 arch12 is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 12 October 2010, 10:33 PM EDT
Posts: 29
Thanks: 2
Thanked 0 Times in 0 Posts
yes did but i put it but but i dont get any reply

---------- Post updated 10-12-10 at 09:06 PM ---------- Previous update was 10-11-10 at 10:35 PM ----------

"set server_list"
couldn't read file "10.144.0.39": no such file or dire
foreach command {10.144.0.36 10.144.0.39} {
ksh: foreach: not found
wer01 linus> spawn ssh $user@$command
ksh: spawn: not found
***** linus> #match_max 100000
a****1 linus> expect "Password:"
couldn't read file "Password:": no such file or directory
send "
ksh: send: not found
123n01 linus> expect -re "apcnn01 linus#"
expect: illegal option -- r
usage: expect [-div] [-c cmds] [[-f] cmdfile] [args]
wer01 linus> send -- "su - linus\r"
ksh: send: not found
wern01 linus> expect "apcnn01 linus>"
couldn't read file "apcnn01 linus>": no such file or directory
wern01 linus> send -- "./apclogcheck.sh"
ksh: send: not found
wer1 linus> #expect -re "awer01 root#"
awer1 linus> #send -- "exit\r"
werenn01 l> interact
ksh: interact: not found
expect eof
couldn't read file "eof": no such file or directory
ksh: syntax error: `}' unexpected
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting genewolfe Shell Programming and Scripting 1 10-01-2009 11:12 AM
how to run shell script inside expect script? robbiezr Shell Programming and Scripting 1 05-06-2009 12:58 PM
strange expect script behavior, or am i misunderstanding expect scripting? v1k0d3n Shell Programming and Scripting 2 12-10-2008 03:31 PM
Using expect script in a shell script or vice versa nua7 Shell Programming and Scripting 0 07-18-2008 07:16 AM
Expect Script HELP zuinc Shell Programming and Scripting 2 04-30-2002 09:42 AM



All times are GMT -4. The time now is 02:58 PM.