function now-time { date +%H%M%S } function now-date { date +%Y%m%d } function now-all { echo $(now-date)-$(now-time) } function psgrep { ps -ef | grep $1 | fgrep -v "grep $1" } # Network connections search function nwgrep { netstat -tulpen | grep $1 | fgrep -v "grep $1" } # History search function hgrep { history | grep $1 | sed '$d' } # Generate random number from $1 to $2 function getrand { echo $(( $RANDOM % ($2 - $1 + 1) + $1 )) } function mkgrx { local i while [ -n "$1" ]; do if [ -z "$i" ]; then i=$1 else i="$i\|$1" fi shift done echo $i } # # Show the actual ip address via checkip.dyndns.org # function checkip () { w3m -dump checkip.dyndns.org | sed 's/Current IP Address://g' } # # # This function I have taken from firehol, the iptables firewall script # # which_cmd() { local block=1 if [ "a${1}" = "a-n" ] then local block=0 shift fi unalias $2 >/dev/null 2>&1 local cmd=`which $2 2>/dev/null| head -n 1` if [ $? -gt 0 -o ! -x "${cmd}" ] then if [ ${block} -eq 1 ] then echo >&2 echo >&2 "ERROR: Command '$2' not found in the system path." echo >&2 " $(basename $0) requires this command for its operation." echo >&2 " Please install the required package and retry." echo >&2 echo >&2 " Note that you need an operational 'which' command" echo >&2 " for $(basename $0) to find all the external programs it" echo >&2 " needs. Check it yourself. Run:" echo >&2 echo >&2 " which $2" echo >&2 #exit 1 fi return 1 fi eval $1=${cmd} return 0 }