title: How to pass multiple servers to an expect script?
body: <p>I'm trying to use an expect script to change my password on multiple servers, but I'm a little confused as to how to pass the list of servers through to it.</p>
  
  <p>The script that I'm using is as follows:</p>
  
  <pre><code>#!/usr/bin/expect -f
  # wrapper to make passwd(1) be non-interactive
  # username is passed as 1st arg, passwd as 2nd
  
  set username [lindex $argv 0]
  set password [lindex $argv 1]
  set serverid [lindex $argv 2]
  set newpassword [lindex $argv 3]
  
  spawn ssh -t $serverid passwd
  expect "assword:"
  sleep 3
  send "$password\r"
  expect "UNIX password:"
  sleep 3
  send "$password\r"
  expect "password:"
  sleep 3
  send "$newpassword\r"
  expect "password:"
  sleep 3
  send "$newpassword\r"
  expect eof
  </code></pre>
  
  <p>And I'm trying to run it as such:</p>
  
  <pre><code>[blah@blah ~]$ ./setkey1 blah password 'cat serverlist' meh
  </code></pre>
  
  <p>which gives me the following output:</p>
  
  <pre><code>spawn ssh -t cat serverid passwd
  ssh: cat serverid: Name or service not known
  send: spawn id exp6 not open
      while executing
  "send "$password\r""
      (file "./setkey1" line 13)
  </code></pre>
  
  <p>So I then tried running the following for loop:</p>
  
  <pre><code>[blah@blah ~]$ for i in serverid; do `cat serverid`; ./setkey1 blah password $i meh; done
  </code></pre>
  
  <p>Which gave me the following:</p>
  
  <pre><code>-bash: staging01v: command not found
  spawn ssh -t serverid passwd
  ssh: serverid: Name or service not known
  send: spawn id exp6 not open
      while executing
  "send "$password\r""
      (file "./setkey1" line 13)
  </code></pre>
  
  <p>If I try using the expect script, and just enter in one server name, it works as...um...expected.</p>
  
  <p>What am I doing wrong?</p>