I have the following script that I feel should loop through the contents of my file that it reads in, but for some reason it is exiting after the first iteration.
#!/usr/bin/bash
scriptDir=/soft/automation/scripts
cd $scriptDir
#LOOP THROUGH THE LIST OF HOSTS AND TEARDOWN/REBUILD EACH
IFS=$IFS,
while read -r name ip vlan image; do
echo "$(date) : Beginning teardown of host ${name}_${vlan}..."
echo "$(date) : Executing command: ./deploy_VM_PureFlex_Nstar.sh -d -n ${name}_${vlan}"
./deploy_VM_PureFlex_Nstar.sh -d -n ${name}_${vlan}
exitCode=$?
if [[ $exitCode -eq 0 ]]; then
echo "$(date) : Teardown of host ${name}_${vlan} completed successfully (exit code: $exitCode). Sleeping for 60 seconds..."
else
echo "$(date) : Teardown of host ${name}_${vlan} completed with errors (exit code: $exitCode). Sleeping for 60 seconds..."
fi
sleep 60
echo "$(date) : Beginning rebuild of vm for host $name"
echo "$(date) : Executing command: ./deploy_VM_PureFlex_Nstar.sh -a -n ${name} -i ${ip} -v ${vlan} -r ${image} -p normal"
./deploy_VM_PureFlex_Nstar.sh -a -n ${name} -i ${ip} -v ${vlan} -r ${image} -p normal
exitCode=$?
if [[ $exitCode -eq 0 ]]; then
echo "$(date) : Rebuild of vm for host ${name}_${vlan} completed successfully (exit code: $exitCode). Sleeping for 60 seconds..."
else
echo "$(date) : Rebuild of vm for host ${name}_${vlan} completed with errors (exit code: $exitCode). Sleeping for 60 seconds..."
fi
sleep 60
done < ${scriptDir}/hosts.txt
Format of the hosts.txt file.
host01,192.168.1.1,5,BaseImg_DB_20150528
host02,192.168.1.2,5,BaseImg_APP_20150528
I feel like I am missing something silly. The thing is if I comment out the 2 lines where it is calling another script it loops just as I would expect. Calling the script is the problem?