Operating System - HP-UX
1820635 Members
1825 Online
109626 Solutions
New Discussion

if else statement in expect script?

 
rleon
Regular Advisor

if else statement in expect script?

Hi

I was wondering if there was a way to an if else statement in an expect script?

I have a file

host1
host2
host3

And a shell script that executes the the expect script and passes the variable.

for host in $(cat $hosts_file)
do
./expect.sh $host
done



#!/usr/local/bin/expect

set timeout 1

set hostname [lindex $argv 0]

spawn telnet $hostname

expect ogin:

send user\r

expect ssword:

send userpass\r

expect ">"

send "exit\r"

expect closed

exit 0

But some of the hostnames are not online or the password failed.

Can you do if else statements in expect?

I would like to log the failures into a logfile.

Thanks
1 REPLY 1
James R. Ferguson
Acclaimed Contributor

Re: if else statement in expect script?

HI:

You might look at:

http://wiki.tcl.tk/11583

Regards!

...JRF...