title: How to pass commands through ssh to dd-wrt with a loop using a variable from a text file?
body: <p>So far I have been able to create a small script using ssh combined with expect to pass a single command through to the dd-wrt router that I am working with. Now that this has been accomplished I wish to pass the same command several times through the ssh log-in instead of just one from a text file, if it is possible.</p>
  
  <p>The other way to accomplish this would be to create a loop and pass the command over, and over again. I would have to use a variable though because the data for the command in the text file changes.</p>
  
  <p>Here is what I have so far</p>
  
  <pre><code>#!/bin/expect -f
  </code></pre>
  
  <p>set password <strong>password</strong></p>
  
  <pre><code>    spawn ssh -l root x.x.x.x -p "command"
      expect "*password:*"
      send -- "$password\r"
      send -- "\r"
  </code></pre>
  
  <p>From what I can see creating a loop would be the easiest way, but I may be wrong. <strong>NOTE</strong> that the "command &amp; variables" that I want to pass through are in a <strong>separate text file</strong>, and that it needs to read/take each line and insert each one into the loop. Unless there is a way to send them through all at once.</p>
  
  <pre><code>#!/bin/expect -f
  </code></pre>
  
  <p>set password <strong>password</strong></p>
  
  <pre><code>    spawn ssh -l root x.x.x.x -p "command Variable" &lt;-- Command to be passed through
      expect "*password:*"
      send -- "$password\r"
      send -- "\r"
  </code></pre>
  
  <p>It is the same command every time in the text file, only the variable changes.</p>
  
  <p>test.txt</p>
  
  <pre><code>command xxxxxxx
  command xxxxxxx
  command xxxxxxx
  command xxxxxxx
  </code></pre>
  
  <p>Thank-you</p>