title: Run script for each line of a file
body: <p>I'm creating a litle script to run some command on all OpenVZ containers inside a node.</p>
  
  <p>I read all OpenVZ containers ID, and I run some commands on all of them.</p>
  
  <p>Instead in the listvz.txt file I have many IDs, the command only runs on the first,
  so the loop not run...</p>
  
  <p>Any idea?
  Thanks!</p>
  
  <pre><code>#! /bin/bash
  export PATH="/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
  
  cat /dev/null &gt; listvz.txt;
  ls -r1 /vz/private &gt; listvz.txt;
  
  cat listvz.txt | while read line; do
  echo FixMySQL in ${line}
  vzctl exec ${line} /etc/init.d/mysql stop;
  vzctl exec ${line} /etc/init.d/mysqld stop;
  vzctl exec ${line} rm -rf /var/lib/mysql/mysql.sock;
  vzctl exec ${line} /etc/init.d/mysql start;
  vzctl exec ${line} /etc/init.d/mysqld start;
  done
  </code></pre>
  
  <p>Result when I run:</p>
  
  <pre><code>[root@ovz ~]# sh mysql-check.sh
  FixMySQL in 2168
  /bin/bash: /etc/init.d/mysql: No such file or directory
  /bin/bash: /etc/init.d/mysqld: No such file or directory
  /bin/bash: /etc/init.d/mysql: No such file or directory
  /bin/bash: /etc/init.d/mysqld: No such file or directory
  [root@ovz1 ~]#
  </code></pre>
  
  <p>Only run on the CTID 2168, but there are much more CTIDs on the TXT file...</p>
  
  <p>Fixed!</p>
  
  <pre><code>cat listvz.txt | while read line; do
  echo FixMySQL in ${line} &lt;/dev/null
  vzctl exec ${line} /etc/init.d/mysqld stop &lt;/dev/null
  vzctl exec ${line} rm -rf /var/lib/mysql/mysql.sock &lt;/dev/null
  vzctl exec ${line} /etc/init.d/mysqld start &lt;/dev/null
  done
  </code></pre>