Bash

From Blue-IT.org Wiki

Revision as of 08:32, 8 January 2014 by Apos (talk | contribs) (Environment)

Environment

Put this in front of any script to avoid problems when running the script in other languages! The en_US locale should be avaiabel on all systems:

export LC_MESSAGES="en_US.UTF-8"
export LC_TYPE="en_US.UTF-8"
export LANGUAGE="en_US.UTF-8


Singleton

The singleton pattern is a very handy one. You can realise it in bash like this:

if ps x | grep -v grep | grep -v $$ | grep $0 | grep -v subl | grep -v vi
then
        echo "$0 already running. Exiting"
        exit 1
else

################################################
# PUT YOUR CODE HERE
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

./run_me

# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
################################################ 
 
fi

Grep and Tail

tail -f -n 300 /var/log/syslog | stdbuf -o0 grep PATTERN