Hash: Search and Purge - 23/06/08 09:41 PM
What's wrong with this code?
This code searches each item's data (ip) in the iptracker has table and checks to see if there is a corresponding same ip (item) in the dns table. If there is not, the ip data value is deleted from the item in the iptracker table.
The problem is that it's not removing all of the ip data values in the iptracker table that don't have a matching ip (item) in the dns table. I'm having to run the alias multiple times and each time it's finding less and less total amount of matches to be removed.
iptracker ex.:
itemname 1.2.3.4 2.3.4.5 3.4.5.6
dns ex.:
2.3.4.5 machine57.hardware.cc
1.2.3.4 green7.newrun.jp
The code above should $remtok 3.4.5.6 from itemname
Code:
alias purgeip { set %a 1 set %b $hget(iptracker,0).item echo 4 -a %b Total items in iptracker table. while (%a <= %b) { set %c $hget(iptracker,%a).item set %d $hget(iptracker,%a).data echo -a %a : %c is %d set %e 1 set %f $numtok(%d,32) while (%e <= %f) { set %g $gettok(%d,%e,32) if (!$hget(dns,%g)) { hadd -s iptracker %c $remtok(%d,%g,32) | set %total $calc(%total + 1) } inc %e } inc %a } echo 4 -a Finished processing %b items in iptracker table! %total total data values purged! unset %a %b %c %d %e %f %g %total }
This code searches each item's data (ip) in the iptracker has table and checks to see if there is a corresponding same ip (item) in the dns table. If there is not, the ip data value is deleted from the item in the iptracker table.
The problem is that it's not removing all of the ip data values in the iptracker table that don't have a matching ip (item) in the dns table. I'm having to run the alias multiple times and each time it's finding less and less total amount of matches to be removed.
iptracker ex.:
itemname 1.2.3.4 2.3.4.5 3.4.5.6
dns ex.:
2.3.4.5 machine57.hardware.cc
1.2.3.4 green7.newrun.jp
The code above should $remtok 3.4.5.6 from itemname