Archivio mensile:ottobre 2018

I miei alias preferiti

Questi sono alcuni alias che preferisco inserire nei miei server ubuntu-like.

Il tutto da inserire in:

nano ~/.bashrc

Script:

alias halt='reboot'
#alias reboot='reboot -f'
alias ll='ls -al'
alias aggiorna='apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y && apt-get autoremove --purge && apt-get autoclean -y'
alias poweroff='reboot'
alias shutdown='reboot'

Script per autogenerare file host

Questo è uno script da poter installare sulla propria macchina server, per autogenerare (con un bel cron) file host da poter poi scaricare con uno script impostato nel vostro router.

Questo per avere file host sempre aggiornati.

#!/bin/bash

rm -rf /opt/ads/*

# Perform work in temporary files
temphosts1=$(mktemp)

# Obtain various hosts files and merge into one
wget -qO - http://winhelp2002.mvps.org/hosts.txt >> $temphosts1
wget -qO - http://hosts-file.net/ad_servers.asp >> $temphosts1
wget -qO - http://someonewhocares.org/hosts/hosts >> $temphosts1
wget -qO - "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext" >> $temphosts1
wget -qO - https://adaway.org/hosts.txt >> $temphosts1
wget -qO - https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts >> $temphosts1

# Do some work on the file:
# 1. Remove MS-DOS carriage returns
# 2. Delete all lines that don't begin with 127.0.0.1
# 3. Delete any lines containing the word localhost because we'll obtain that from the original hosts file
# 4. Replace 127.0.0.1 with 0.0.0.0 because then we don't have to wait for the resolver to fail
# 5. Scrunch extraneous spaces separating address from name into a single tab
# 6. Delete any comments on lines
# 7. Clean up leftover trailing blanks
# Pass all this through sort with the unique flag to remove duplicates and save the result

sed -e 's/\r//' -e '/^127.0.0.1/!d' -e '/localhost/d' -e 's/127.0.0.1/0.0.0.0/' -e 's/ \+/\t/' -e 's/#.*$//' -e 's/[ \t]*$//' < $temphosts1 | sort -u > /opt/ads/hosts

rm /var/www/MIOSITO/hosts.txt
ln /opt/ads/hosts /var/www/MIOSITO/hosts.txt

exit 0