touch facebook

athibault
New Contributor

if you go into JAMF there is a script to block touch facebook, but it doesn't work.
I have look at the script, and I can't see anything wrong.

!/bin/bash

# swipely-host.sh

Check for certain entry in /etc/hosts

Add the entry if it's not found

Adam Codega, Swipely

Built off of http://thecodecave.com/2010/11/03/adding-a-line-to-etchosts-via-bash/

change domain to url you wish to block. subdomain would be www, m or anything else.

SUCCESS=0
domain=facebook.com
needle=touch.$domain
hostline="127.0.0.1 $needle"
filename=/etc/hosts

Determine if the line already exists in /etc/hosts

grep -q "$needle" "$filename" # -q is for quiet. Shhh...

Grep's return error code can then be checked. No error=success

if [ $? -eq $SUCCESS ]
then exit 0;
else # If the line wasn't found, add it using an echo append >> echo "$hostline" >> "$filename" # Let's recheck to be sure it was added. grep -q "$needle" "$filename"

if [ $? -eq $SUCCESS ] then exit 0; else exit 1; fi
fi
Help
Anne

4 REPLIES 4

adamcodega
Valued Contributor

Hi Anne
It looks like you found my script from this Jamf Nation thread. It looks like some lines were combined into one by accident.

If you look a the line that begins with else, there's a pound symbol, which is how you start a comment in a Shell script. So everything after that symbol is "commented out" and is not read by the computer as commands to run. You need to start a new line beginning at echo "$hostline" so it looks like this:

else # If the line wasn't found, add it using an echo append >>
echo "$hostline" >> "$filename" # Let's recheck to be sure it was added.
grep -q "$needle" "$filename"

The if statement that follows it looks fine the way you've formatted it.

Also on Jamf Nation you can format your post so that a script is displayed in it's own block quote. When posting, click the >_ button next to the bold/italics buttons and the quotation button. Then you can paste your script in to help readability.

adamcodega
Valued Contributor

Also, are you blocking touch.facebook.com on macOS devices? That looks like the Facebook's website for iOS.

athibault
New Contributor

sorry, no dice.

adamcodega
Valued Contributor

@athibault What happens when Jamf runs the script? Is there an error message?