loops - Bash script not looping as expected -
this question has answer here:
i have following script feel should loop through contents of file reads in, reason exiting after first iteration.
#!/usr/bin/bash scriptdir=/soft/automation/scripts cd $scriptdir #loop through list of hosts , teardown/rebuild each ifs=$ifs, while read -r name ip vlan image; 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 ]]; echo "$(date) : teardown of host ${name}_${vlan} completed (exit code: $exitcode). sleeping 60 seconds..." else echo "$(date) : teardown of host ${name}_${vlan} completed errors (exit code: $exitcode). sleeping 60 seconds..." fi sleep 60 echo "$(date) : beginning rebuild of vm 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 ]]; echo "$(date) : rebuild of vm host ${name}_${vlan} completed (exit code: $exitcode). sleeping 60 seconds..." else echo "$(date) : rebuild of vm host ${name}_${vlan} completed errors (exit code: $exitcode). sleeping 60 seconds..." fi sleep 60 done < ${scriptdir}/hosts.txt
format of hosts.txt file.
host01,192.168.1.1,5,baseimg_db_20150528 host02,192.168.1.2,5,baseimg_app_20150528
i feel missing silly. thing if comment out 2 lines calling script loops expect. calling script problem?
your hosts.txt
file not posix compliant , contains no newline
@ end of file. need:
while read -r name ip vlan image || [ -n "$image" ];
in order read final line. see why should files end newline?
Comments
Post a Comment