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


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.


rm -rf /opt/ads/*

# Perform work in temporary files

# Obtain various hosts files and merge into one
wget -qO - >> $temphosts1
wget -qO - >> $temphosts1
wget -qO - >> $temphosts1
wget -qO - "" >> $temphosts1
wget -qO - >> $temphosts1
#wget -qO - >> $temphosts1
wget -qO - >> $temphosts1

# Do some work on the file:
# 1. Remove MS-DOS carriage returns
# 4. Replace with because then we don't have to wait for the resolver to fail
# 2. Delete all lines that don't begin with
# 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 's/' -e '/^!d' -e 's/ \+/\t/' -e 's/#.*$//' -e 's/[ \t]*$//' < $temphosts1 | sort -u >  /opt/ads/hosts

#remove the first line
sed -i -e "1d" /opt/ads/hosts

L=$(wc -l /opt/ads/hosts | awk '{ print $1 }')
NOW="#$L hosts  $(date +"%d/%m/%Y %H:%M:%S")"

sed -i "1 i\\$NOW" /opt/ads/hosts

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

exit 0