#parse(), #split()
DESCRIPTION
decompose a string into parts assigned to the variables $1, $2, ...,
where whitespace (space or tab) separates the constituent parts,
returning the number of parts
or:
decompose a string into parts assigned to the variables $1, $2, ...,
using the given field separators for the decomposition, returning
the number of parts
or:
decompose a string into parts; if given a regular expression containing
one or more () pairs, the matching constituent parts are assigned to
$1, $2, ..., and the entire expression match is assigned to $0;
returns the matched parts
or:
decompose a string into parts, using the specified field separators,
and assigning the parts to the specified variable name, returning
the number of parts
SYNOPSIS
#parse(s)
#split(s)
or:
#parse(s1,s2)
#split(s1,s2)
or:
#parse(s1,s2)
#split(s1,s2)
or:
#parse(s1,s2,s3)
#split(s1,s2,s3)
ARGUMENTS
s - a string, or string expression
or:
s1 - a string, or string expression
s2 - a string, or string expression (field separators)
or:
s1 - a string, or string expression
s2 - a string, or string expression (regular expression)
or:
s1 - a string, or string expression (variable name)
s2 - a string, or string expression
s3 - a string, or string expression (field separators)
EXAMPLES
do #split($command("=wc -l /etc/NIS/passwd"))
set #lcurr = #val($1)
do #split($command("=wc -l /etc/NIS/passwd.nightly.backup"))
set #lback = #val($1)
rule
do #split($command("=lld $dev"))
set $access = $1
set #links = #value($2)
set $owner = $3
set $group = $4
set $major = $5
set $minor = $6
set $mon = $7
set $date = $8
set $time = $9
set $name = $10
end
if #innum() == 0 // this reports if the ypservers file
// is empty; if the file is missing,
// that would generate a stat() error
// in the alert log file
output mail "=ypservers empty!"
else // report missing servers
set #ns = #split("=nisserver")
for #i=1 #i<=#ns #i+=1
if ! #defined(#nisservers[$[#i]])
output mail "missing server?: $[#i]"
fi
endfor
fi
rule
do #split($time, ":")
set #hour_reboot = #val($1)
rule // set the zombie count (if any)
if #parse($inlin, "([[:digit:]]+)[[:space:]]zombie") == 1
// new regexp, so possibly new $1
set #zombnum = #val($1)
else
set #zombnum = 0
fi
begin
// record all accounts in passwd file in #passwd[] array
if #fopen(PASSWD, "=passwd", "r") != #err()
while #read(PASSWD) > 0
do #split($p, $rdlin, ":")
if $p[1] eq "+"
cont
fi
=incr(#passwd[=strip($p[1],"+")])
endwhile
do #fclose(PASSWD)
else
output mail "can't open =passwd for reading!"
quit
endif
set_fa(F) // set age of file in days; this presupposes that (F) exists,
// unless (F) is not supplied (invoked as: =set_fa()) so
// $mon, $date & $time are already known for the current file
if "(F)" eq "" // as with: =set_fa()
set #fa = #fileage($mon,$date,$time)
else // as with: =set_fa("=passwd")
if ! #defined($mon)
set $mon = $nil()
fi
if ! #defined($date)
set $date = $nil()
fi
if ! #defined($time)
set $time = $nil()
fi
do #split($command("=lld (F)"))
set #fa = #fileage($[6],$[7],$[8])
endif
rule
if #split($dur, "-:") == 4
set #days = #val($1)
set #hours = #val($2)
set #minutes = #val($3)
set #seconds = #val($4)
elsif #split($dur, "-:") == 3
set #days = 0
set #hours = #val($1)
set #minutes = #val($2)
set #seconds = #val($3)
else
set #days = 0
set #hours = 0
set #minutes = #val($1)
set #seconds = #val($2)
fi
set #minutes_total = #days * 60 * 24 + #hours * 60 + #minutes
rule // addresses not of the form "foo"
if #parse($addr, "@") != 2
=outputmail $inlin
=mailmsg2($inlin, bad address\, please fix, $recipient)
next
fi
set $acct = $1
set $site = $2
rule // addresses of the form ""
if $acct eq ""
=outputmail $inlin
=mailmsg2($inlin, bad address\, please fix, $recipient)
next
fi
rule // addresses not of the form ""; by implication,
// includes addresses of the form "foo@"
if #parse($site, ".") !> 1
=outputmail $inlin
=mailmsg2($inlin, bad address\, please fix, $recipient)
next
fi
rule // report forward DNS resolution mismatches
set #h = #split($nishosts)
for #i=1 #i<=#h #i+=1
set $dnsaddress = $trim($command("=nslookup $[#i] 2>/dev/null |
=tail +4 |
=awk -F: '/^Address:/ {print \$2}'"))
if $dnsaddress eq ""
# ifdef verbose
output mail "$[#i] not registered in DNS"
set #problem = #true()
# endifdef
else
if $dnsaddress ne $nisaddr
output mail "$[#i] DNS resolves to $dnsaddress,
fails to match NIS address $nisaddr"
set #problem = #true()
endif
endif
endfor
rule // nonexistent grpmem
// the apjpr group applies to the gsbapj? machines
if $group =~ "stata|apjpr|dxoffice"
next
endif
set #memnum = #split($mem, $grpmem, ",")
for #i=1 #i<=#memnum #i+=1
if $mem[#i] =~ "root|bin|noone|\\+\@"
cont
endif
if $command("=ypmatch $mem[#i] passwd 2>&1") =~~ "no such"
output mail "for group $group, unknown member $mem[#i]"
endif
endfor
SEE ALSO
Numerical Functions
String Functions