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
# Simple Bash Hash Generator | |
# | |
# Author: Chris Hager <[email protected]> | |
# | |
# Put the `hashgen` method in your `.functions` file and source it from your `.bash_profile` | |
# | |
# Usage: hashgen [type] [#chars] | |
# | |
# Optional argument `type`: | |
# |
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
start on runlevel [2345] | |
stop on runlevel [016] | |
respawn | |
respawn limit 10 10 | |
kill signal INT | |
kill timeout 20 | |
normal exit 0 TERM INT |
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
declare -rx IFC='/sbin/ifconfig' | |
showips() { | |
NAMES=( $($IFC | egrep 'lo|eth|wlan|en' -A 1 | awk -F' ' '{print $1 }' | egrep -v 'inet|-|UP|RX|collisions' | sort -u) ) | |
for i in "${NAMES[@]}"; do | |
echo "$i has ip address: $($IFC | grep $i -A 1 | grep 'addr' | awk -F' ' '{print $2}' | awk -F':' '{print $2}')" | |
done |
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
Check if BASH_ENV is empty | |
set umask 077 | |
Reset $PATH and $IFS | |
ALWAYS - use absolute path names | |
Check return codes from system utilities. | |
Signify the end of the option list with -- | |
Quote all command line parameters (e.g. "$1") | |
Check user input for shell metacharacters and garbage | |
Check user supplied pathnames (absolute/relative) | |
set shell option noclobber to avoid overwriting existing files |
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
# diplay alphabetically sorted list of processes with open files | |
# 'file' means: regular file, directory, block special, character special, executing text reference, library, stream or network file (Internet socket, NFS file or UNIX domain socket) | |
lsof | awk '{print $1}' | sort -u | |
# display all files that apache2 has open | |
# | |
lsof -c apache2 | less |
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
# display a random number based on the number of lines in a file | |
echo $(($RANDOM%`grep -c '$' ~/.bash_history`)) | |
# replace COMMAND to find all the libboost libraries it is using | |
lsof | grep 'COMMAND.*mem.*libboost' | |
# display contents of file without comments or empty lines, also removes "in-line" comments | |
# this is an example of a reason to NOT USE IN LINE COMMENTS | |
egrep -v '#|^$' /etc/mysql/my.cnf |
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
# one line command below | |
ssh -X -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o StrictHostKeyChecking=no \ | |
-i /Users/veryv/.ssh/google_compute_engine -A -p 22 [email protected] -- | |
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
needs file descriptor and something like this | |
exec 10>$temp | |
<$temp> | |
#!/bin/bash - | |
# track path & filename for tempfile | |
temp="./example.tmp" |
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
# fast & efficient triple check: | |
# existence, directory, writable || or error and exit | |
[[ -e $DIR && -d $DIR && -w $DIR ]] || { echo >&2 "Unable to access $DIR - check directory path / permissions?" ; exit 1 ; } | |
# exists , file, readable | |
[[ -s $FILE && -d $FILE && -r $FILE ]] || { echo >&2 "Unable to access $FILE - check file path / permissions?" ; exit 1 ; } | |
# exists , file, writable | |
[[ -s $FILE && -d $FILE && -w $FILE ]] || { echo >&2 "Unable to access $FILE - check file path / permissions?" ; exit 1 ; } |
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
# closure - defined by Peter Landin in 1964 | |
# closure - a function, plus a pointer to that functions scope | |
# In programming languages, closures (also lexical closures or function closures) are a technique for | |
# implementing lexically scoped name binding in languages with first-class functions. Duh. | |
# Operationally, a closure is a record storing a function[a] together with an environment:[1] | |
# A mapping associating each free variable of the function (variables that are used locally, but defined in an enclosing scope) | |
# with the value or storage location to which the name was bound when the closure was created. |