<div dir="ltr">So should I go ahead and make the changes to the script that I suggested?<div><br></div><div>Thanks,</div><div>BJ</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 8, 2015 at 3:21 PM, Eric Blake <span dir="ltr"><<a href="mailto:eblake@redhat.com" target="_blank">eblake@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 06/08/2015 02:43 PM, Laine Stump wrote:<br>
>> However, if I changed the destination address from "anywhere" to the<br>
>> IP of the host machine, the problem resolved. So I change the script<br>
>> to as follows. (Changes are highlighted. For some reason the original<br>
>> script didn't work using /bin/sh, but it did with /bin/bash, so I<br>
>> changed that too).<br>
><br>
> I don't know for sure, but my guess is that this line:<br>
><br>
>   length=$(( ${#Host_port[@]} - 1 ))<br>
<br>
</span>Correct - that line is a bashism, and is not portable when /bin/sh is dash.<br>
<span class=""><br>
><br>
> which was added by vgerris in order to support forwarding of multiple<br>
> ports, could be what's causing the incompatibility (that wasn't in the<br>
> original, simpler version of the script, written by me.)<br>
><br>
>><br>
</span>>> *#!/bin/bash*<br>
<span class="">>> # used some from advanced script to have multiple ports: use an equal<br>
>> number of guest and host ports<br>
>><br>
>> Guest_name=xxxxxxx<br>
>> Guest_ipaddr=xxx.xxx.xxx.xx<br>
</span>>> *Host_ipaddr=xxx.xxx.xxx.xx*<br>
<span class="">>> Host_port=( '80' '443' )<br>
>> Guest_port=( '80' '443' )<br>
<br>
</span>In fact, these two lines are also bashisms.  All the more reason to<br>
require bash.<br>
<span class=""><br>
>> length=$(( ${#Host_port[@]} - 1 ))<br>
>> if [ "${1}" = "${Guest_name}" ]; then<br>
>>    if [ "${2}" = "stopped" -o "${2}" = "reconnect" ]; then<br>
<br>
</span>test ... -o ... (also spelled [ ... -o ... ]) is not portable, even on<br>
bash.  There are some expressions that are completely ambiguous on how<br>
to be parsed, when -o is in the mix.  It is better to spell it: [ ... ]<br>
|| [ ... ] (that is, use the shell's || instead of test's -o to do the<br>
conjunction).<br>
<span class=""><br>
>>        for i in `seq 0 $length`; do<br>
<br>
</span>seq is not portable outside of GNU/Linux systems.<br>
<span class=""><br>
>> Lastly, I should note that I am using Ubuntu 14.04, both for the host<br>
>> and guest.<br>
<br>
</span>Yep, that's a system that uses dash for /bin/sh.<br>
<span class=""><br>
>><br>
>> I'm also curious as to why this is considered a hack method. It states<br>
>> in the wiki that "This method is a hack", but it doesn't express why.<br>
><br>
> I consider it a hack because:<br>
><br>
> 1) It requires the IP address of the guest to be known before the guest<br>
> is started, so either you need to guess the guest's IP (if the guest is<br>
> getting its IP address via dhcp) or configured the guest IP address in<br>
> multiple places.<br>
<br>
</span>Although recent work has been made to get libvirt to add an API that<br>
queries the guest for its IP address, once the guest is running.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Eric Blake   eblake redhat com    <a href="tel:%2B1-919-301-3266" value="+19193013266">+1-919-301-3266</a><br>
Libvirt virtualization library <a href="http://libvirt.org" rel="noreferrer" target="_blank">http://libvirt.org</a><br>
<br>
</font></span></blockquote></div><br></div>