# mob3.awk function rmspace(s) { gsub(/ /,"",s) gsub(/\//,"-",s) gsub(/['"]/, "", s) return s } function clip(s) { sub(/[ \t]*$/,"",s) gsub(/\//,"-",s) gsub(/['"]/, "", s) return s } function ld_t21gengroup(t21gengroupfile) { printf("ld_t21gengroup(%s)\n", t21gengroupfile) nggs = 0 while ( (getline aline < t21gengroupfile) > 0 ) { #print "aline: " aline ++nggs #gg_arr[nggs] = aline split(aline, a_arr, "|") f = 0 gg_childgroupid = clip(a_arr[++f]) gg_parentgroupid = clip(a_arr[++f]) gg_hierarid = clip(a_arr[++f]) gg_childgrid_to_parentgrid_arr[gg_childgroupid] = gg_parentgroupid gg_childgrid_to_hierarid_arr[gg_childgroupid] = gg_hierarid #print " gg_childgrid_to_parentgrid_arr[" gg_childgroupid "]=[" gg_childgrid_to_parentgrid_arr[gg_childgroupid] "]" } close(t21gengroupfile) print "ld_t21gengroup: nggs = " nggs } function ld_t21groupname(t21groupnamefile) { printf("ld_t21groupname(%s)\n", t21groupnamefile) ngns = 0 while ( (getline aline < t21groupnamefile) > 0 ) { #print "aline: " aline ++ngns #gn_arr[ngns] = aline split(aline, a_arr, "|") f = 0 gn_siteid = clip(a_arr[++f]) gn_grid = clip(a_arr[++f]) gn_grtype = clip(a_arr[++f]) gn_grlevel = clip(a_arr[++f]) gn_grname1 = clip(a_arr[++f]) gn_grname2 = clip(a_arr[++f]) gn_hierarid = clip(a_arr[++f]) gn_tarifftype = clip(a_arr[++f]) gn_routeid = clip(a_arr[++f]) gn_grid_arr[gn_grid] = 1 gn_grid_to_siteid_arr[gn_grid] = gn_siteid gn_grid_to_grtype_arr[gn_grid] = gn_grtype gn_grid_to_grlevel_arr[gn_grid] = gn_grlevel gn_grid_to_grname1_arr[gn_grid] = gn_grname1 gn_grid_to_grname2_arr[gn_grid] = gn_grname2 gn_grid_to_hierarid_arr[gn_grid] = gn_hierarid gn_grid_to_tarifftype_arr[gn_grid] = gn_tarifftype gn_grid_to_routeid_arr[gn_grid] = gn_routeid # leave Staff Ditr Current flag intact ## flag not current #if ( gn_grlevel > 0 ) # gn_grid_to_grname2_arr[gn_grid] = sprintf("%-23.23sNC", gn_grid_to_grname2_arr[gn_grid]) } close(t21groupnamefile) print "ld_t21groupname: ngns = " ngns } function ld_t21gnextra(t21gnextrafile) { printf("ld_t21gnextra(%s)\n", t21gnextrafile) ngnes = 0 while ( (getline aline < t21gnextrafile) > 0 ) { #print "aline: " aline ++ngnes #gne_arr[ngnes] = aline split(aline, a_arr, "|") f = 0 gne_grid = clip(a_arr[++f]) gne_grname3 = clip(a_arr[++f]) gne_grid_to_grname3_arr[gne_grid] = gne_grname3 } close(t21gnextrafile) print "ld_t21gnextra: ngnes = " ngnes } function ld_t21directtemplate(t21directtemplatefile) { printf("ld_t21directtemplate(%s)\n", t21directtemplatefile) maxdtrecordno = 0 ndts = 0 nskipext0 = 0 nskipextlen2to3 = 0 while ( (getline aline < t21directtemplatefile) > 0 ) { #print "aline: " aline ++ndts #dt_arr[ndts] = aline split(aline, a_arr, "|") f = 0 recordno = clip(a_arr[++f]) secure_code = clip(a_arr[++f]) alternateno = clip(a_arr[++f]) branch = clip(a_arr[++f]) building = clip(a_arr[++f]) department = clip(a_arr[++f]) division = clip(a_arr[++f]) extgroupunique = clip(a_arr[++f]) extgroupname = clip(a_arr[++f]) equipcode = clip(a_arr[++f]) equip_type = clip(a_arr[++f]) exchangeline = clip(a_arr[++f]) extension = clip(a_arr[++f]) faxnumber = clip(a_arr[++f]) firstinit = clip(a_arr[++f]) floor = clip(a_arr[++f]) general1 = clip(a_arr[++f]) general2 = clip(a_arr[++f]) generalmode = clip(a_arr[++f]) fgroup = clip(a_arr[++f]) location = clip(a_arr[++f]) mailbox = clip(a_arr[++f]) fmode = clip(a_arr[++f]) pstnaccess = clip(a_arr[++f]) pstnindial = clip(a_arr[++f]) prefname = clip(a_arr[++f]) prefix = clip(a_arr[++f]) rsc = clip(a_arr[++f]) routing = clip(a_arr[++f]) site = clip(a_arr[++f]) status = clip(a_arr[++f]) surname = clip(a_arr[++f]) telephone = clip(a_arr[++f]) title = clip(a_arr[++f]) if ( recordno > maxdtrecordno ) maxdtrecordno = recordno dt_recordno_arr[recordno] = 1 dt_recordno_to_secure_code_arr[recordno] = secure_code dt_recordno_to_extgroupunique_arr[recordno] = extgroupunique dt_recordno_to_extension_arr[recordno] = extension dt_recordno_to_fgroup_arr[recordno] = fgroup dt_recordno_to_site_arr[recordno] = site # use status (1) to flag notcurrent/activenotcurrent/current # keep Staff Dir status dt_recordno_to_status_arr[recordno] = status # only set Not Current or Active if not set by Staff Dir if ( dt_recordno_to_status_arr[recordno] != "C" ) { if (active_siteextension_arr[site "|" extension] == 1) dt_recordno_to_status_arr[recordno] = "A" else dt_recordno_to_status_arr[recordno] = "N" } else { # Currenty from Staff Dir staffdir_siteextension_to_recordno_arr[site "|" extension] = recordno #print "DBG: load got staffdir_siteextension_to_recordno_arr[" site "|" extension "]=[" staffdir_siteextension_to_recordno_arr[site "|" extension] "]" } recordno_skipext0_arr[recordno] = 0 if ( extension == 0 ) { recordno_skipext0_arr[recordno] = 1 ++nskipext0 } extlen = length(extension) recordno_skipextlen2to3_arr[recordno] = 0 if ( extlen >= 2 && extlen <= 3 ) { recordno_skipextlen2to3_arr[recordno] = 1 ++nskipextlen2to3 } } close(t21directtemplatefile) new_recordno = maxdtrecordno + 1 print "ld_t21directtemplate: ndts = " ndts print " nskipext0 = " nskipext0 print " nskipextlen2to3 = " nskipextlen2to3 print " maxdtrecordno = " maxdtrecordno } function ld_t21directcustom(t21directcustomfile) { printf("ld_t21directcustom(%s)\n", t21directcustomfile) ndcs = 0 nskipnotmaster = 0 nskipothermaster = 0 while ( (getline aline < t21directcustomfile) > 0 ) { #print "aline: " aline ++ndcs #dc_arr[ndcs] = aline split(aline, a_arr, "|") f = 0 recordno = clip(a_arr[++f]) familyname = clip(a_arr[++f]) givenname = clip(a_arr[++f]) speeddial = clip(a_arr[++f]) telephone = clip(a_arr[++f]) title = clip(a_arr[++f]) fulltitle = clip(a_arr[++f]) position = clip(a_arr[++f]) department = clip(a_arr[++f]) location = clip(a_arr[++f]) privatemobile = clip(a_arr[++f]) filt_privatemobile = clip(a_arr[++f]) companymobile = clip(a_arr[++f]) filt_companymobile = clip(a_arr[++f]) roomsphone = clip(a_arr[++f]) filt_roomsphone = clip(a_arr[++f]) faxno = clip(a_arr[++f]) filt_faxno = clip(a_arr[++f]) homephone = clip(a_arr[++f]) filt_homephone = clip(a_arr[++f]) extpagerno = clip(a_arr[++f]) weekendphone = clip(a_arr[++f]) filt_weekendphone = clip(a_arr[++f]) intpagerno = clip(a_arr[++f]) empid = clip(a_arr[++f]) email = clip(a_arr[++f]) printed_listed = clip(a_arr[++f]) web_listed = clip(a_arr[++f]) master = clip(a_arr[++f]) terminated = clip(a_arr[++f]) date_updated = clip(a_arr[++f]) dc_recordno_to_familyname_arr[recordno] = familyname dc_recordno_to_givenname_arr[recordno] = givenname dc_recordno_to_speeddial_arr[recordno] = speeddial dc_recordno_to_telephone_arr[recordno] = telephone dc_recordno_to_title_arr[recordno] = title dc_recordno_to_fulltitle_arr[recordno] = fulltitle dc_recordno_to_position_arr[recordno] = position dc_recordno_to_department_arr[recordno] = department dc_recordno_to_location_arr[recordno] = location dc_recordno_to_privatemobile_arr[recordno] = privatemobile dc_recordno_to_filt_privatemobile_arr[recordno] = filt_privatemobile dc_recordno_to_companymobile_arr[recordno] = companymobile dc_recordno_to_filt_companymobile_arr[recordno] = filt_companymobile dc_recordno_to_roomsphone_arr[recordno] = roomsphone dc_recordno_to_filt_roomsphone_arr[recordno] = filt_roomsphone dc_recordno_to_faxno_arr[recordno] = faxno dc_recordno_to_filt_faxno_arr[recordno] = filt_faxno dc_recordno_to_homephone_arr[recordno] = homephone dc_recordno_to_filt_homephone_arr[recordno] = filt_homephone dc_recordno_to_extpagerno_arr[recordno] = extpagerno dc_recordno_to_weekendphone_arr[recordno] = weekendphone dc_recordno_to_filt_weekendphone_arr[recordno] = filt_weekendphone dc_recordno_to_intpagerno_arr[recordno] = intpagerno dc_recordno_to_empid_arr[recordno] = empid dc_recordno_to_email_arr[recordno] = email dc_recordno_to_printed_listed_arr[recordno] = printed_listed dc_recordno_to_web_listed_arr[recordno] = web_listed dc_recordno_to_master_arr[recordno] = master dc_recordno_to_terminated_arr[recordno] = terminated dc_recordno_to_date_updated_arr[recordno] = date_updated extension = dt_recordno_to_extension_arr[recordno] site = dt_recordno_to_site_arr[recordno] recno = dt_siteextension_to_recordno_arr[site "|" extension] #print "DBG: " #print "DBG: ld_t21d... recordno=" recordno " site=" site " extension=" extension " master=" master if ( recno != "" ) { # already have site|extension #print "DBG: Already have recno=" recno " for site=" site " extension=" extension " master=" dc_recordno_to_master_arr[recno] recordno_skipnotmaster_arr[recordno] = 0 if ( master == "Y" ) { if ( dc_recordno_to_master_arr[recno] == "Y" ) { #print "DBG: skip master recordno=" recordno # skip this master if already have # a master for site|extension recordno_skipothermaster_arr[recordno] = 1 ++nskipothermaster } else { #print "DBG: replace non-master with this recordno=" recordno # replace first non-master recno # for site|extension with this master dt_siteextension_to_recordno_arr[site "|" extension] = recordno recordno_skipnotmaster_arr[recno] = 1 ++nskipnotmaster } } else { # skip non master recs #print "DBG: skip non-master recordno=" recordno recordno_skipnotmaster_arr[recordno] = 1 ++nskipnotmaster } } else { # first occurance of site|extension #print "DBG: flag first occurance of site=" site " extension=" extension " master=" master dt_siteextension_to_recordno_arr[site "|" extension] = recordno } #print " dt_siteextension_to_recordno_arr[" site "|" extension "]=[" dt_siteextension_to_recordno_arr[site "|" extension] "]" t21name = toupper(givenname) if ( t21name != "" && familyname != "" ) t21name = t21name " " t21name = t21name toupper(familyname) dc_t21name_to_recordno_arr[t21name] = recordno print " dc_t21name_to_recordno_arr[" t21name "]=[" dc_t21name_to_recordno_arr[t21name] "]" } close(t21directcustomfile) print "ld_t21directcustom: ndcs = " ndcs print " nskipnotmaster = " nskipnotmaster print " nskipothermaster = " nskipothermaster } function ld_t21mobconf(t21mobconffile) { printf("ld_t21mobconf(%s)\n", t21mobconffile) nggs = 0 while ( (getline aline < t21mobconffile) > 0 ) { #print "aline: " aline split(aline, a_arr, "|") f = 0 recordno = clip(a_arr[++f]) mobile = clip(a_arr[++f]) customid = clip(a_arr[++f]) sdate = clip(a_arr[++f]) edate = clip(a_arr[++f]) directoryid = clip(a_arr[++f]) groupid = clip(a_arr[++f]) datatype = clip(a_arr[++f]) purchased = clip(a_arr[++f]) supplier = clip(a_arr[++f]) manufacturer = clip(a_arr[++f]) model = clip(a_arr[++f]) carriercode = clip(a_arr[++f]) servicetype = clip(a_arr[++f]) introaming = clip(a_arr[++f]) gprs = clip(a_arr[++f]) simnumber = clip(a_arr[++f]) imeinumber = clip(a_arr[++f]) puk = clip(a_arr[++f]) dataplan = clip(a_arr[++f]) contractstart = clip(a_arr[++f]) contractfinish = clip(a_arr[++f]) archivecomment = clip(a_arr[++f]) updated = clip(a_arr[++f]) msg1 = clip(a_arr[++f]) msg2 = clip(a_arr[++f]) msg3 = clip(a_arr[++f]) msg4 = clip(a_arr[++f]) msg5 = clip(a_arr[++f]) msg6 = clip(a_arr[++f]) msg7 = clip(a_arr[++f]) msg8 = clip(a_arr[++f]) msg9 = clip(a_arr[++f]) mobile_mobconf_aline_arr[mobile] = aline #print "mobile_mobconf_aline_arr[" mobile "]=[" mobile_mobconf_aline_arr[mobile] "]" # store a slist og curretn configured mobiles print " mobile=[" mobile "]" " edate=[" edate "]" if ( edate == "" ) { if ( directoryid != "-1" ) mobile_mobconf_current_directoryid_arr[mobile] = directoryid if ( groupid != "" ) mobile_mobconf_current_groupid_arr[mobile] = groupid mobile_mobconf_current_recordno[mobile] = recordno print " mobile_mobconf_current_recordno[" mobile "]=[" mobile_mobconf_current_recordno[mobile] "]" } } close(t21mobconffile) } function ld_unallocmobiles(unallocmobilesfile) { printf("ld_unallocmobiles(%s)\n", unallocmobilesfile) nunallocmobiles = 0 while ( (getline aline < unallocmobilesfile) > 0 ) { #print "aline: " aline split(aline, a_arr, ",") f = 0 mobile = clip(a_arr[++f]) ++nunallocmobiles unalloc_mobile_arr[mobile] = "1" print " unalloc_mobile_arr[" mobile "]=[" unalloc_mobile_arr[mobile] "]" } close(unallocmobilesfile) print "ld_t21gengroup: nunallocmobiles = " unallocmobiles } #-------------------------------- BEGIN { system("rm -f mob3_new.unl") ld_t21gengroup("gengroup.unl") ld_t21groupname("groupname.unl") ld_t21gnextra("gnextra.unl") ld_t21directtemplate("directtemplate.unl") ld_t21directcustom("directcustom.unl") ld_t21mobconf("mobconf.unl") ld_unallocmobiles(unallocmobfile) print "brss=[" brss "]" print "BEGIN..." } { if ( NR == 1 ) next # skip header print "" print "----------------------------------------" print $0 print "" f = 0 CC = clip($++f) Mobile_Number = clip($++f) Name_Desc = clip($++f) ++reccount mob3_mobile = rmspace(Mobile_Number) print "CC=[" CC "]" " Mobile_Number=[" Mobile_Number "]" " (mob3_mobile=[" mob3_mobile "])" print "Name_Desc=[" Name_Desc "]" name_desc = Name_Desc sub(/- MobileNet/, "", name_desc) name_desc = clip(name_desc) print "name_desc=[" name_desc "]" # look to see if its in the unallac_mobile list # (from the mobile import verify report email) unalloc_mobile = unalloc_mobile_arr[mob3_mobile] if ( unalloc_mobile == "1" ) { print "UNALLOC: in the unalloacted mobile verify report" ++unalloc_cnt } # look to see if its current mobe in the t21 mobconf config mobconf_recordno = mobile_mobconf_current_recordno[mob3_mobile] print "mobconf_recordno=[" mobconf_recordno "]" mobconf_directoryid = mobile_mobconf_current_directoryid_arr[mob3_mobile] mobconf_groupid = mobile_mobconf_current_group_arr[mob3_mobile] if ( mobconf_recordno != "" ) { print "mobconf_directoryid=[" mobconf_directoryid "]" print " mobconf_groupid=[" mobconf_groupid "]" print "SKIP: already found in mobconf" ++skip_inmobconf_cnt } else { print "NOTCONF: NOT in mobconf" # eg. #13092|0408186370|mobile_phones|23/02/2016||-1|A0160|5||Telstra|||t||||||||||manual|23/02/2016|Cath Team Leader phone||||||||| recordno = "0" # new serial mobile = mob3_mobile customid = "mobile_phones" sdate = "01/01/2016" edate = "" directoryid = "-1" groupid = CC datatype = "5" purchased = "" supplier = "Telstra" manufacturer = "auto rjs bulk" model = "" carriercode = "t" servicetype = "" introaming = "" gprs = "" simnumber = "" imeinumber = "" puk = "" dataplan = "" contractstart = "" contractfinish = "" archivecomment = "manual" updated = today msg1 = name_desc msg2 = "" msg3 = "" msg4 = "" msg5 = "" msg6 = "" msg7 = "" msg8 = "" msg9 = "" mobconfrec = sprintf("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|", recordno, mobile, customid, sdate, edate, directoryid, groupid, datatype, purchased, supplier, manufacturer, model, carriercode, servicetype, introaming, gprs, simnumber, imeinumber, puk, dataplan, contractstart, contractfinish, archivecomment, updated, msg1, msg2, msg3, msg4, msg5, msg6, msg7, msg8, msg9) print "Adding mobconfrec=[" mobconfrec "]" print mobconfrec > "mob3_new.unl" } # in unalloacted list && NOT in mobconf if ( unalloc_mobile == "1" && mobconf_recordno == "" ) { ++inunalloclist_and_not_inmobconf print "UNALLOCNOTCONF: in unalloacted list and NOT in mobconf" } # see if its a name in the Telmax21 Directory split(name_desc,name_desc_arr, " ") maybe_firstname = name_desc_arr[1] maybe_surname = name_desc_arr[2] maybe_t21name = toupper(maybe_firstname) if ( maybe_t21name != "" && maybe_surname != "" ) maybe_t21name = maybe_t21name " " maybe_t21name = maybe_t21name toupper(maybe_surname) print "maybe_t21name=[" maybe_t21name "]" recordno = dc_t21name_to_recordno_arr[maybe_t21name] if ( recordno != "" ) { print "FOUND: T21 Dir recordno=[" recordno "]" if ( mobconf_recordno != "" && recordno != mobconf_directoryid ) { print "DIRECTORYID: mismatch" ++directoryid_mismatch_cnt } ++found_t21dir_cnt } } END { print "END:" print "+++++++++++++++++++++++++++++++++++++++++++++" print "nunallocmobiles = " nunallocmobiles pruint "" print "reccount = " reccount print "" print " unalloc_cnt = " unalloc_cnt print " skip_inmobconf_cnt = " skip_inmobconf_cnt print "inunalloclist_and_not_inmobconf = " inunalloclist_and_not_inmobconf print " found_t21dir_cnt = " found_t21dir_cnt print " directoryid_mismatch_cnt = " directoryid_mismatch_cnt print "" print "+++++++++++++++++++++++++++++++++++++++++++++" print "create new mobconf data" for ( mobile in new_mobconf_arr ) { print "add mobile=[" mobile "]" } print "" }