Any good tutorials or sites for expect scripting?

In a nutshell here is what I am trying to do:

I have a file with a list of hostnames. I want to read in the file and ssh to each hostname on the list. Do some commands, logout of the server and go onto the next on the list.

I am trying to find a site that is a good tutorial or examples so I can learn how to do more than just the basics with expect.

Thanks

Robert

hope this will help..

Thanks...but I am looking for help with expect scripting and reading in files, not the actual use of SSH.

From reading this -- I don't see a reason to have to use expect.

You can execute commands on a remote system through ssh.

chris@host01> ssh host02 uptime
Password:
 11:25am  up 5 day(s), 14:17,  5 users,  load average: 0.07, 0.03, 0.02

I'm sure you noticed I still entered a passwd. Ok so you setup your ssh keys between hosts so you don't have to enter a passwd.

So you parse your file to get your list of hostnames.
I have no idea the particulars of you situation -- So I am making stuff up.

cat file
somethinghere host1 somethingthere
somethinghere host2 somethingthere
somethinghere host3 somethingthere
somethinghere host4 somethingthere

FILE=your_file_here
HOSTS=`awk '{print $2}' $FILE`

for x in $HOSTS;do
	ssh $x "date;uptime;df -k /"
done 

This will execute date, uptime, and the df on all four hosts...

I use a script I made called forhost to do similar tasks. I work often on hundreds of machines in series, executing one -- or more commands on the host then moving on to the next host.

$1 is the command/commands you want to run and $2 is you list of boxes...
Here is how to use it:

chris@host01> cat tmp.lst
host-ap551
host-db501
host-ww501
host-ww502
chris@host01>./forhost "uptime;date" tmp.lst
host-ap551 is alive
SYSTEM :: host-ap551     1:20pm  up 16 day(s),  5:47,  11 users,  load average: 3.09, 3.02, 2.99
Tue Aug 26 13:20:12 CDT 2008

host-db501 is alive
SYSTEM :: host-db501     1:20pm  up 16 day(s), 6 hr(s),  40 users,  load average: 4.45, 4.35, 4.62
Tue Aug 26 13:20:14 CDT 2008

host-ww501 is alive
SYSTEM :: host-ww501     1:20pm  up 9 day(s),  1:55,  3 users,  load average: 0.41, 0.38, 0.39
Tue Aug 26 13:20:16 CDT 2008

host-ww502 is alive
SYSTEM :: host-ww502     1:20pm  up 9 day(s),  1:54,  24 users,  load average: 5.52, 5.41, 4.09
Tue Aug 26 13:20:21 CDT 2008

Or....

chris@host01>./forhost "uptime;date" " host-ww503 host-ww504"
host-ww503 is alive
SYSTEM :: host-ww503     1:22pm  up 16 day(s),  3:36,  9 users,  load average: 1.20, 1.37, 1.32
Tue Aug 26 13:22:07 CDT 2008

host-ww504 is alive
SYSTEM :: host-ww504     1:22pm  up 12 day(s), 14:17,  20 users,  load average: 0.68, 0.89, 1.32
Tue Aug 26 13:22:09 CDT 2008

Or.....

chris@host01>./forhost "uptime;date" "`grep db tmp.lst`"
host-db501 is alive
SYSTEM :: host-db501     1:24pm  up 16 day(s),  6:04,  41 users,  load average: 4.34, 4.35, 4.56
Tue Aug 26 13:24:13 CDT 2008

And here is the script.....

#!/bin/ksh
#### Determine if $1 $2 are present
if [[ -z $1 || -z $2 ]];then
        print "Useage: $0 \"command 1;command 2;command 3\"  list of servers"
        print "command may be one or more commands eperated by ;"
        print "any spaces in command sequence require wrapping in \" \""
        print " "
        print "the list of servers can be a file. If so any line containing # will be omitted"
        print "or the list can be a few hosts wrapped in \" \""
else
        continue
fi
#### Determine if $2 is a file or not
if [[ -f $2 ]]
then
        LIST=`grep -v '#' $2|sort`
else
        LIST=$2
fi
for SYSLIST in $LIST
do
        ## Check and see if $x is alive
        #UP=`ping $SYSLIST 2`
        if ping $SYSLIST 2
        then
                #### Execute a command on SYSTEM defined in $LIST
                ssh -q $SYSLIST "echo \"SYSTEM :: `echo $SYSLIST`   \c\";$1;echo ' '"
        else
                echo "$SYSLIST is Down? "
        fi
done

Thanks that has helped a lot.