bash snippets¶
100% Load 4 CPU cores¶
for i in 1 2 3 4; do while : ; do : ; done & done
show my ip¶
$ dig +short myip.opendns.com @resolver1.opendns.com
remove old files¶
Find and clean files in a directory and its subdirectories:
/usr/bin/find /dir -maxdepth 2 \( -name "access*.gz" -o -name "error*.gz" \) -a -mtime +178 -print0 | xargs -0 rm -vf 2>&1 | logger
template¶
#!/bin/bash
# ./script [-t DAYS] -a AGE -d DIR
# -t today date
# ex: ./script -a 366 -d /srv/log
DAY_ZERO=0
LOG_DIR="/usr/local/empty"
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# Logging tag
LTAG="$(basename $0)[$$]"
do_log() {
logger -t $LTAG "$*"
}
do_log "Started with params $*"
# Script params
while [ "$#" -ge "2" ] ; do
case $1 in
-t)
DAY_ZERO=$2
shift 2 ;;
-a)
AGE=$2
shift 2 ;;
-d)
LOG_DIR=$2
shift 2 ;;
*) shift 1 ;;
esac
done
find_in_dir() {
}
find_in_dir $LOG_DIR $AGE
do_log "Finished."
exit 0