diff options
Diffstat (limited to 'src/pmdas/sample/get_next_pmid')
-rwxr-xr-x | src/pmdas/sample/get_next_pmid | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/pmdas/sample/get_next_pmid b/src/pmdas/sample/get_next_pmid new file mode 100755 index 0000000..5443a7d --- /dev/null +++ b/src/pmdas/sample/get_next_pmid @@ -0,0 +1,48 @@ +#!/bin/sh +# +# find next unallocated PMIDs for the sample PMDA +# + +if [ $# -gt 1 ] +then + echo "Usage: $0 [N]" + echo "N defaults to 1 (PMID to generate)" + exit 1 +fi +want=1 +[ $# -eq 1 ] && want="$1" + +root=root +if [ ! -f $root ] +then + root=../root +fi +if [ ! -f $root ] +then + echo "Error: cannot find PMNS in root nor ../root" + exit 1 +fi + +pminfo -m -n $root \ +| sed -n -e '/ 29/s/\(.*\): \(.*\)/\2 \1/p' \ +| sort -t . -n -k 1,1 -k 2,2 -k 3,3 \ +| sed -e 's/ .*//' -e 's/\./ /g' \ +| awk ' +BEGIN { lastidx = -1; found = 0 } +NF != 3 { next } +$2 != 0 { next } + { if (lastidx+1 != $3) { + for (i = lastidx+1; i < $3; i++) { + print "SAMPLE:0:" i + found++ + if (found == '"$want"') exit + } + } + lastidx = $3 + } +END { while (found < '"$want"') { + lastidx++ + print "SAMPLE:0:" lastidx + found++ + } + }' |