Last active
August 29, 2015 14:00
-
-
Save flaudisio/11390811 to your computer and use it in GitHub Desktop.
Snippets avulsos para o Bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# shell-utils: snippets avulsos para o Bash | |
PLAYGROUND="/tmp/playground" | |
ANO="$( date +'%Y' )" | |
cria_dir_esqueleto_ano() | |
{ | |
# Cria um diretório-esqueleto de ano não-bissexto (YYYY/MM/DD) | |
# (pode ser útil para testes de backups) | |
mkdir -pv "$PLAYGROUND/$ANO"/{{04,06,09,11}/{01..30},{01,03,05,07,08,10,12}/{01..31},02/{01..28}} | |
} | |
mostra_primeiro_e_ultimo_dias_dos_meses() | |
{ | |
# Retorna o primeiro e último dia de cada mês no diretório criado | |
# por "cria_dir_esqueleto_ano()" | |
find "$PLAYGROUND/$ANO" -mindepth 2 -maxdepth 2 \ | |
| egrep '([0-9][0-9]/01|02/28|(04|06|09|11)/30|(01|03|05|07|08|10|12)/31)$' \ | |
| sort | |
} | |
# Lista os pacotes um dia instalados via 'aptitude install' e que | |
# ainda se encontram presentes no sistema (instalados) | |
lista_pacotes_instalados_via_aptitude_e_ainda_presentes() | |
{ | |
zegrep -i '^\[INSTALL]' /var/log/aptitude* \ | |
| cut -d ' ' -f 2- \ | |
| cut -d ':' -f 1 \ | |
| sort -u \ | |
| egrep -v '^lib' \ | |
| while read package ; do | |
echo -n "$package: " | |
dpkg --get-selections | egrep -q "^${package}[[:blank:]]+install$" | |
[[ $? -eq 0 ]] && echo "YES" || echo "NO" | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment