I want to append/add one line entry in the exist file on windows & unix environment.
File name :: ClientAgent.cfg
Entry to be added ::SITE_CONTROLLER_ADDRESS=192.x.x.x
Here I want to check one condition like whether we have any line entry present SITE_CONTROLLER_ADDRESS=
( without any IP address assigned ) and add my new IP address .
on edit: I forgot to mention that I only wrote it for Windows, but it shouldnât be too hard to extrapolate to Linux/Unix. Let me know if you need help
Itâs crude, but it works. You can take it and make it pretty by changing the hard path filename with a parameter or anything else you like.
Itâs only relevant on computers where:
The file âc:\temp\ClientAgent.cfgâ exists
The file âc:\temp\ClientAgent.cfgâ has a line containing âSITE_CONTROLLER_ADDRESSâ and its value is empty
What it does:
When you take the action it asks you for the IP Address you want to assign to that field
dumps the content of the âClientAgent.cfgâ file to a __createfile (without the line containing âSITE_CONTROLLER_ADDRESSâ and appends a new âSITE_CONTROLLER_ADDRESSâ field along with the value of the IP Address you specified
Deletes the old âClientAgent.cfgâ file
Moves the __createfile to be the new âClientAgent.cfgâ file
In case you have trouble seeing the item in bigfix.me:
Relevance:
clause 1: exists file âC:\temp\ClientAgent.cfgâ
clause 2: following text of first â=â of (lines of file âc:\temp\ClientAgent.cfgâ as string) whose (it contains âSITE_CONTROLLER_ADDRESSâ) = ââ
Action Script:
action parameter query âipaddressâ with description âEnter the value to add to the âSITE_CONTROLLER_ADDRESSâ field:â
delete __createfile
createfile until EOF
{concatenation â%0D%0Aâ of ((it) as string) whose (it does not contain âSITE_CONTROLLER_ADDRESS=â) of (lines of file âc:\temp\ClientAgent.cfgâ)}
SITE_CONTROLLER_ADDRESS={parameter âipaddressâ}
EOF
dos del /F âc:\temp\ClientAgent.cfgâ
move __createfile âC:\temp\ClientAgent.cfgâ
I hope that helps. If you find an error and need some help just post here again.
I havenât really tested this, but I think the following should hopefully get you started for the actionscript portion:
action parameter query "sitecontrolleraddress" with description "Please enter Site Controller Address IP value:"
delete __appendfile
appendfile {concatenation "%0d%0a" of ((lines whose (it as lowercase does not start with "site_controller_address=") of it;"SITE_CONTROLLER_ADDRESS=" & parameter "sitecontrolleraddress" of action) of file "R:\panacesagent.cfg")}
This will query the operator for the desired IP address value, then prepare an appendfile (which will later have to be moved to replace the .cfg file) that contains all the lines of the cfg file except any that contain âsite_controller_addressâ, and append the additional line as specified.
action parameter query âsitecontrolleraddressâ with description âPlease enter Site Controller Address IP value:â
delete __appendfile
appendfile {concatenation â%0d%0aâ of ((lines whose (it as lowercase does not start with âPANACES_SITE_CONTROLLER_ADDRESS=â) of it;âPANACES_SITE_CONTROLLER_ADDRESS=â & parameter âsitecontrolleraddressâ of action) of file â/tmp/scripttest/PanacesAgentGeneric.cfgâ)}
copy â/tmp/scripttest/PanacesAgentGeneric.cfgâ â/tmp/scripttest/PanacesAgentGeneric.cfg.backupâ
PANACES_MASTER_SERVER_ADDRESS=10.x.x.x
PANACES_SLAVE_SERVER_ADDRESS=10.x.x.x
PANACES_AGENT_NODE_ADDRESS=10.x.x.x
PANACES_AGENT_NODE_BIND_ADDRESS= PANACES_SITE_CONTROLLER_ADDRESS= ( this suppose to add IP here )
IS_SERIALCALL_ENABLED=false PANACES_SITE_CONTROLLER_ADDRESS=10.x.x.x ( instead , its added one more entry in the last line )
My requirement is
if file has already line entry has ( PANACES_SITE_CONTROLLER_ADDRESS= ), use the same input value ( PANACES_SITE_CONTROLLER_ADDRESS= ) & use parameter to append the new IP
If file doesnât have ( PANACES_SITE_CONTROLLER_ADDRESS= ) entry, add new line with new IP .
Sorry I am not getting you. Please help me to fix this problem . Thanks.
Do you mean, remove this "%0d%0a" from action ?
appendfile {concatenation "%0d%0a" of ((lines whose (it as lowercase does not start with âsite_controller_address=â) of it;âSITE_CONTROLLER_ADDRESS=â & parameter âsitecontrolleraddressâ of action) of file âR:\panacesagent.cfgâ)}
No, that %0d%0a is what puts the newlines between the linesâŚyou need another one
appendfile {concatenation "%0d%0a" of ((lines whose (it as lowercase does not start with "site_controller_address=") of it;"%0d%0aSITE_CONTROLLER_ADDRESS=" & parameter "sitecontrolleraddress" of action) of file "R:\panacesagent.cfg")}
On Linux/UNIX/Mac youâll probably need to use %0a instead of %0a, as those operating systems use a different end-of-line character for text files. So youâll need separate blocks in your action based on
if {Windows of operating system}
// Use the action above
Else
// Use the action above with %0a instead of %0d%0a and use a different file path
Endif
#cat PanacesAgentGeneric.cfg
PANACES_MASTER_SERVER_ADDRESS=10.x.x.x
PANACES_SLAVE_SERVER_ADDRESS=10.x.x.x
PANACES_AGENT_NODE_ADDRESS=10.x.x.x PANACES_SITE_CONTROLLER_ADDRESS= ( either this entry has to be removed atleast )
PANACES_AGENT_NODE_BIND_ADDRESS= PANACES_SITE_CONTROLLER_ADDRESS=10.x.x.x
IS_SERIALCALL_ENABLED=false
That is because your ârequirementsâ changed halfway through this thread.
Just change the bits that refer to âsite_controller_addressâ to you new value
Everything you need is in the previous post. Change the strings you were asking us to change before, to match the strings youâre asking us to change now.