(imported comment written by itowns91)
Ben,
Thanks so much for this. It looks like you got the idea completely. Here’s what happened when I deployed it.
The action has been run 1 time, and will not be run again.
The action failed.
Completed: // store the file location
Completed: parameter “filename” = “d:\nrpc\siteinfo.dat”
Completed: // store the remote IP address from the “remote host ip address” line
Failed: parameter “remoteip” = "{(parenthesized part of match (case insensitive regex "remote host ip address\s*(
http://\w.
+)") of it) of line whose (exists match (case insensitive regex "remote host ip address\s*(
http://\w.
+)") of it ) of file (parameter “filename”)}"
// if the "ndss router ip exists, then add a “1” to it and store it in a variable, otherwise store blank string
parameter “routerip” = "{if (exists lines whose (exists match (case insensitive regex "NDSS Router IP Address\s*(
http://\w.
+)") of it ) of file (parameter “filename”)) then (parenthesized part of match (case insensitive regex "NDSS Router IP Address\s*(
http://\w.
+)") of line whose (exists match (case insensitive regex "NDSS Router IP Address\s*(
http://\w.
+)") of it ) of file (parameter “filename”) ) & “1” else “”}"
// iterate through the file replacing lines as necessary
appendfile {concatenation “%0d%0a” of ( if (it contains “SiteInfo.Dat file for”) then (preceding text of first "SiteInfo.Dat file for " of it) & "SiteInfo.Dat file for " & (computer name) else if (it contains “SPS SortPlan Site Name”) then (preceding text of first "SPS SortPlan Site Name " of it) & "SPS SortPlan Site Name " & (computer name) else if (it contains “NDSS Router IP Address”) then (preceding text of first "NDSS Router IP Address " of it) & "NDSS Router IP Address " & (parameter “routerip”) else it ) of lines of file (parameter “filename”)}
// then if we don’t have the last line, add it:
if {not exists (parameter “routerip”) OR (parameter “routerip”) = “”}
appendfile {"(14) NDSS Router IP Address " & (preceding text of last “.” of parameter “remoteip”) & “.11”}
endif
// backup the old file
move “{parameter “filename”}” “{parameter “filename”}.bak”
// replace with the new file
move __appendfile “{parameter “filename”}”
The actual file text that we are working with:
Time last updated: 11/7/2007 5:15:12 PM
(0) SiteInfo.Dat file for
Disclaimer: This file should only be updated through
NRPC Setup by authorized personnel. Do not directly
update this ASCII file!
(1) Remote Host IP Address x.x.x.47
(2) Auto Start Time 8:00:00 PM
(3) NRPC Log File Creation Date 5/4/05 12:28:50 PM
(4) SPS SortPlan Site Name TESTSITE
(5) AFSM100 Files Window Enable/Disable False
(6) DBCS Files Window Enable/Disable True
(7) DIOSS Files Window Enable/Disable False
(8) FSM881 Files Window Enable/Disable False
(9) FSM1000 Files Window Enable/Disable False
(10) MPBCS Files Window Enable/Disable False
(11) SPBS Files Window Enable/Disable False
(12) Reports Add/Remove Site Code to Filename True
(13) Send Reports to NDSS/DCS NDSS