Skip to content

Commit 6f7d97c

Browse files
author
Razvan Becheriu
committed
[#2914] extended documentation with for loops in scripts
1 parent 1b8b359 commit 6f7d97c

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

doc/sphinx/arm/hooks-run-script.rst

+37-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ An example of a script implementing all hook points is presented below:
8585

8686
::
8787

88-
#!/bin/bash
88+
#!/bin/sh
8989

9090
unknown_handle() {
9191
echo "Unhandled function call ${*}"
@@ -625,3 +625,39 @@ at 0.
625625
LEASE6_PREFERRED_LIFETIME
626626
LEASE6_PREFIX_LEN
627627
LEASE6_TYPE
628+
629+
The leases4_committed hook point needs for loops to handle the list of addresses.
630+
This can be achived in the following way:
631+
632+
::
633+
634+
leases4_committed() {
635+
for i in $(seq 0 $((LEASES4_SIZE-1))); do
636+
LEASE4_ADDRESS=$(eval "echo \$LEASES4_AT${i}_ADDRESS")
637+
...
638+
done
639+
640+
for i in $(seq 0 $((DELETED_LEASES4_SIZE-1))); do
641+
DELETED_LEASE4_ADDRESS=$(eval "echo \$DELETED_LEASES4_AT${i}_ADDRESS")
642+
...
643+
done
644+
exit 0
645+
}
646+
647+
The leases6_committed hook point needs for loops to handle the list of addresses.
648+
This can be achived in the following way:
649+
650+
::
651+
652+
leases6_committed() {
653+
for i in $(seq 0 $((LEASES6_SIZE-1))); do
654+
LEASE6_ADDRESS=$(eval "echo \$LEASES6_AT${i}_ADDRESS")
655+
...
656+
done
657+
658+
for i in $(seq 0 $((DELETED_LEASES6_SIZE-1))); do
659+
DELETED_LEASE6_ADDRESS=$(eval "echo \$DELETED_LEASES6_AT${i}_ADDRESS")
660+
...
661+
done
662+
exit 0
663+
}

src/hooks/dhcp/run_script/run_script.dox

+41-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ the hook point.
101101
An example of a script implementing all hook points is presented below.
102102

103103
@code
104-
#!/bin/bash
104+
#!/bin/sh
105105

106106
unknown_handle() {
107107
echo "Unhandled function call ${*}"
@@ -666,6 +666,46 @@ LEASE6_TYPE
666666

667667
@endcode
668668

669+
The leases4_committed hook point needs for loops to handle the list of addresses.
670+
This can be achived in the following way:
671+
672+
@code
673+
674+
leases4_committed() {
675+
for i in $(seq 0 $((LEASES4_SIZE-1))); do
676+
LEASE4_ADDRESS=$(eval "echo \$LEASES4_AT${i}_ADDRESS")
677+
...
678+
done
679+
680+
for i in $(seq 0 $((DELETED_LEASES4_SIZE-1))); do
681+
DELETED_LEASE4_ADDRESS=$(eval "echo \$DELETED_LEASES4_AT${i}_ADDRESS")
682+
...
683+
done
684+
exit 0
685+
}
686+
687+
@endcode
688+
689+
The leases6_committed hook point needs for loops to handle the list of addresses.
690+
This can be achived in the following way:
691+
692+
@code
693+
694+
leases6_committed() {
695+
for i in $(seq 0 $((LEASES6_SIZE-1))); do
696+
LEASE6_ADDRESS=$(eval "echo \$LEASES6_AT${i}_ADDRESS")
697+
...
698+
done
699+
700+
for i in $(seq 0 $((DELETED_LEASES6_SIZE-1))); do
701+
DELETED_LEASE6_ADDRESS=$(eval "echo \$DELETED_LEASES6_AT${i}_ADDRESS")
702+
...
703+
done
704+
exit 0
705+
}
706+
707+
@endcode
708+
669709
@section libdhcp_run_scriptMTCompatibility Multi-Threading Compatibility
670710

671711
The Run Script hooks library is compatible with multi-threading.

0 commit comments

Comments
 (0)