Help with editing hosts file on Mac/Linux

(imported topic written by fdooling)

I need help in editing the hosts file on approximately 250 Macs in our department and have not been able to find any info on how to do this. The action script I have tried is below but it keeps failing:

// Add new entry to /private/etc/hosts

waithidden sudo /bin/sh -c “echo ‘127.0.0.1 new.entry.com’ >> /private/etc/hosts”

Any help would be greatly appreciated

(imported comment written by NoahSalzman)

A couple thing to try: 1) get rid of sudo, the agent is already root. 2) try running this using the “shell script” option in the action versus action script. For that latter test you will need to remove the waithidden, of course.

(imported comment written by jgstew)

This analysis will not help you write this task, but it will help you see what is in place already in the endpoints’ host files:
http://bigfix.me/analysis/details/2994561

(imported comment written by jgstew)

Also, you might try:

waithidden echo “127.0.0.1 new.entry.com” >> /private/etc/hosts

Try create "hostfilesh"
Content of hostsh
Echo “ip server” >> /private/etc/hosts

Chmod 755 hostfilesh
Wait /bin/sh hostfilesh

1 Like