iPXE discussion forum
Scripting question - Printable Version

+- iPXE discussion forum (https://forum.ipxe.org)
+-- Forum: iPXE user forums (/forumdisplay.php?fid=1)
+--- Forum: General (/forumdisplay.php?fid=2)
+--- Thread: Scripting question (/showthread.php?tid=14859)



Scripting question - ebruno - 2018-10-18 01:13

I have following script:

set attempt:int32 0
set maxtries:int32 5
:retry_dhcp
sleep 5
inc attempt
iseq ${attempt} ${maxtries} && goto max_attempts ||
echo DHCP Attempt ${attempt} of ${maxtries}
dhcp || goto retry_dhcp
.....

max_attempts:
....

The values of maxtries and attempt are displayed with expected values by the echo statement. But the attempt equals 5 the script does got to max_attempts.

I tried iseq ${attempt} 5 && goto mac_attempts first but that did not work either.

What is the recommend way to test two numeric values .


RE: Scripting question - MultimediaMan - 2018-10-18 03:40

The good news is your code is working. The problem is that the dhcp command is broad statement to test for. I would recommend using "dhcp net0" instead of just "dhcp"... another behavior I have observed is that it is best to test a subsequent expected condition brought on by the "dhcp net0" command. For instance check to see if there is a default gateway ${net0/gateway} or an IP set ${net0/ip} ;

Sample Code:

Code:
set 0_lp:int32 0 ; inc 0_lp

:0_retry echo DHCP Attempt ${0_lp} ; dhcp net0 || inc 0_lp
isset ${net0/gateway} && goto 0_dns || goto 0_usrnpu
iseq ${0_lp} 4 && goto 0_usrnpu || sleep 2 ; goto 0_retry



RE: Scripting question - ebruno - 2018-10-18 16:32

(2018-10-18 03:40)MultimediaMan Wrote:  The good news is your code is working. The problem is that the dhcp command is broad statement to test for. I would recommend using "dhcp net0" instead of just "dhcp"... another behavior I have observed is that it is best to test a subsequent expected condition brought on by the "dhcp net0" command. For instance check to see if there is a default gateway ${net0/gateway} or an IP set ${net0/ip} ;

Sample Code:

Code:
set 0_lp:int32 0 ; inc 0_lp

:0_retry echo DHCP Attempt ${0_lp} ; dhcp net0 || inc 0_lp
isset ${net0/gateway} && goto 0_dns || goto 0_usrnpu
iseq ${0_lp} 4 && goto 0_usrnpu || sleep 2 ; goto 0_retry

Thanks much, your response is helpful.