I am trying to append an entry into the HOSTS file, it seems like it should be simple, but everything I have tried fails. I used the suggestion that Ben posted for “Appending Text To a File in a Fixlet/Task/Action” and wrote a couple of actions. After a few failures, I have edited the action to it’s simplest form:
run cmd.exe /C echo {“X.X.X.X Our-Server-01.any.domain.dcd”} >> {“c:\windows\system32\drivers\etc\hosts”}
(I did not set any relevance at all)
It fails also. Any help would be greatly appreciated.
If you made this Fixlet message, the console will report “Failed” if the applicability relevance does not switch from true to false. Tasks return “Completed” if all lines of the action complete successfully.
Here’s a little relevance for PCs that don’t have “X.X.X.X Our-Server-01.any.domain.dcd”
exists file "hosts"
whose
(
not exists lines
whose
(
it != ""
and
it as left trimmed string starts with "X.X.X.X"
and
it as right trimmed string as lowercase ends with “our-server-01.any.domain.dcd”
)
of it
)
of folder “drivers\etc” of system folder
Obviously X.X.X.X is an IP address, which is why I don’t lowercase it.
I’m also checking via “starts with” rather than “contains” because it could have the IP address commented out with a “#”.