Skip to content

Instantly share code, notes, and snippets.

@RonanKER
RonanKER / context.prop
Last active November 10, 2019 00:08
shell script execution "framework" - centralize head&tail of a bunch of scripts & externalise context parameters
export SRC_DATA_DIR=/home/user/source
export DEST_DATA_DIR=/home/user/destination
export DATE_EXEC=${DATE_EXEC:-$(date +%Y%m%d_%H%M%S)}
export TMP_DIR=/tmp/myscripttmpdir
export LOGS_DIR=$SCRIPT_DIR/logs
export SRC_DB_USER=user
export SRC_DB_PASSWD=password
export SRC_DB_NAME=db1
@RonanKER
RonanKER / diskInfo.sh
Created February 14, 2018 23:52
Classic simple script to give disk info
#!/bin/sh
DISC=$1
[ -z "$DISC" ] && DISC=/
PARTITION=`df -h |grep $DISC |awk '{print $1}'`
SIZE=`df -h|grep $DISC|awk '{print $2}'`
USED=`df -h|grep $DISC|awk '{print $3}'`
FREE=`df -h|grep $DISC|awk '{print $4}'`
@RonanKER
RonanKER / testRollFile.sh
Created February 14, 2018 23:34
a test about cleaning oldest files matching pattern in a directory
#Exemple of configurable cleaner for oldest file in a directory
# Use case of this exemple :
# * a script that uses a temp file (writing timestamp in its name for exemple)
# * by default it removes its temp file at the end (and only this one)
# * for debug purpose we would like to keep the file, or several historic files
# * with "KEEP_FILE" we can set : 0 (clean all) 1 (only latest) X (youngest files) "ALL" (keep all files)
#configuration
TARGET_DIR=~/tmp/test
KEEP_FILE=3
@RonanKER
RonanKER / remove_old_files.sh
Created February 14, 2018 23:30
remove_old_files.sh by Seb Dangerfield
#!/bin/bash
# http://www.sebdangerfield.me.uk/2011/02/old_file_removal_bash-script/
# ex: ./remove_old_files.sh 30 /home/myuser/large_file_count_dir
if [ $# -ne 2 ] ; then
echo "Not enough arguments.
Please pass the number of files to keep followed by the path"
exit 1
fi
# First argument is the number of files to keep!
KEEP_NUM=$1
@RonanKER
RonanKER / .bashrc
Created February 14, 2018 23:24
My Bashrc File
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
@RonanKER
RonanKER / dumpCPUStack.sh
Last active November 9, 2019 23:50
Quick dump htop+top+threadDump for analysis to identify CPU top consumer in a Java process (ex: Tomcat)
#!/bin/bash
COUNTER=2
TARGETDIR=/home/jalios/dumpCPUStack
PID=$(cat /home/jalios/instance/tomcat.pid)
#PID=$(ps h -fu tomcat | grep jplatform | awk '{print $2}')
echo "This script will dump $COUNTER times the threads stacks and CPU usage for process pid=$PID"
while [ $COUNTER -gt 0 ]; do