- 16 Jan 2025
- 2 読む分
- 印刷する
- PDF
Unblock Websites
- 更新日 16 Jan 2025
- 2 読む分
- 印刷する
- PDF
Use this script to unblock the websites defined in the script, that may have been blocked using the block websites script.
Copy and save the contents below to a UTF-8 editor like notepad++ OR Sublime Text in Windows or gedit in Ubuntu.
If you are using notepad++ then use the bottom right panel to change the type to Unix (LF).
Click here to download the file.
#!/bin/bash # Function to check if the script is running as root check_root() { if [ "$(id -u)" -ne 0 ]; then echo "Please run this script as root or using sudo." exit 1 fi } # Function to create a backup of the /etc/hosts file backup_hosts_file() { cp /etc/hosts /etc/hosts.bak if [ $? -ne 0 ]; then echo "Failed to create a backup of /etc/hosts. Exiting." exit 1 fi echo "Backup of /etc/hosts created at /etc/hosts.bak." } # Function to unblock websites unblock_websites() { websites=("facebook.com" "youtube.com" "mail.google.com") for website in "${websites[@]}"; do # Check if the website is present in the /etc/hosts file if grep -q "$website" /etc/hosts; then # Remove the website entry from the /etc/hosts file sed -i "/$website/d" /etc/hosts if [ $? -eq 0 ]; then echo "$website unblocked successfully." else echo "Error: Failed to unblock $website." fi else echo "No entry found for $website in /etc/hosts." fi done } # Function to verify changes and notify the user verify_changes() { # Compare the original and modified files to confirm changes if cmp -s /etc/hosts /etc/hosts.bak; then echo "No changes were made to unblock websites." else echo "Websites unblocked successfully." fi } # Main Script Execution check_root # Ensure the script is run as root backup_hosts_file # Create a backup of the /etc/hosts file unblock_websites # Unblock websites from the /etc/hosts file verify_changes # Verify if changes were made and notify the user
In the script, insert the URLs to be unblocked against the placeholder:
unblock_websites() {
websites=
For example,
unblock_websites() { websites=("facebook.com" "youtube.com" "mail.google.com")
Follow our guide to upload & publish the script using Scalefusion Dashboard.
Note:
Some of the scripts and their contents are sourced from internet and yes, our new friend ChatGPT.
Please validate the scripts on a test machine before deploying them on all your managed devices.
Scalefusion has tested these scripts, however Scalefusion will not be responsible for any loss of data or system malfunction that may arise due to the usage of these scripts.