drop all mysql databases

#!/bin/bash
# Remove all mysql databases

echo 'Enter MySQL user'
read MYSQL_USER

echo 'Enter MySQL password'
stty -echo
read MYSQL_PASSWD
stty echo

DATABASES=$( mysql -u $MYSQL_USER -p$MYSQL_PASSWD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database )

for i in ${DATABASES[*]}; do

  if [ $i != 'mysql' ] && [ $i != 'information_schema' ] && [ $i != 'performance_schema' ]; then

    echo $( date +%H:%M ) drop database: $i 
    time mysql -u $MYSQL_USER -p$MYSQL_PASSWD -e "DROP DATABASE $i"
  fi
done

script to recalculate vmware disk size

#!/bin/bash
# Recalculate vmware thin disk size

# Creates zero-block file in all free disk space 
for i in $(df | grep '^/dev/' | awk '{print $6}'); do
  if [ $i == '/' ];then
    echo 'creating a file of blocks zeroed in:' ${i}zerofile
    dd if=/dev/zero of=${i}zerofile bs=4096; rm -f ${i}zerofile
  else
    echo 'creating a file of blocks zeroed in:' $i/zerofile
    dd if=/dev/zero of=$i/zerofile bs=4096; rm -f $i/zerofile
  fi
done

After run the command with the machine turned off in ESXi Host

vmkfstools --punchzero /vmfs/volumes/path-to-disk.vmdk

CPU, Memory Usage by Apache

APACHE PROCESSES THAT CPU OR MEMORY IS LARGER THAN 0

ps -A --sort -rss -o pid,comm,pmem,pcpu,lstart | grep httpd | awk '($3>0) || ($4>0)'

TOTAL CPU USED BY THE APACHE PROCESS

ps -A --sort -rss -o pid,comm,pmem,pcpu | grep httpd | awk '{n+=$4} END {print n"%"}'

TOTAL MEMORY USED BY THE APACHE PROCESS

ps -A --sort -rss -o pid,comm,pmem,pcpu | grep httpd | awk '{n+=$3} END {print n"%"}

Imprimir na Saída Padrão e Gerar Log Linux

Gera log em /var/log com nome file.log

echo $( date '+%F') msg | tee -a /var/log/file.log

Gera log redirecionando erro e saída padrão em /var/log com nome file.log

echo $( date '+%F') msg 2>&1 | tee -a /var/log/file.log

Gera log em /var/log com nome do script .log

date | tee -a /var/log/$( basename $0 ).log

Gera log no dieretório que está o script com nome file.log

date | tee -a $( dirname $0 )/file.log

Gera log no dieretório que está o script com nome do script .log

date | tee -a $( dirname $0 )/$( basename $0 ).log