Atrixnet Code Share and Geek Resources | Can you grok it?

TAG | bash

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
export PS1="\n[\[\e[1;37m\]\u\[\e[0m\]@\[\e[1;34m\]\H\[\e[0m\]] [\[\e[1;33m\]\d, \t\[\e[0m\]] [\[\e[1;31m\]\!\[\e[0m\]]\n\[\e[1;31m\]\[\e[0m\][\[\e[1;37m\]\w\[\e[0m\]]\n\[\e[1;37m\]\\$\[\e[0m\] "
export HISTTIMEFORMAT='%F %T '
export HISTCONTROL=ignoredups
export HISTCONTROL=ignoreboth
export HISTIGNORE='pwd:ls:history:'
eval `dircolors`
alias ls='ls --color=auto'
alias dir='ls --color=auto --format=vertical'
alias ll='ls -Al'
alias la='ls -A'
alias lh='ls -Alh'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias dateclip='date|xsel --clipboard'
alias tsclip='echo -n "$(date +%Y-%m-%d-%H.%M.%S)"|xsel --clipboard'
alias tstmp='date +%Y-%m-%d-%H.%M.%S'
alias cryptclip="xsel|gpg -ear ace@tommybutler.me|xsel --clipboard"
alias putclip="xsel --clipboard"
alias getclip="xsel"
alias procstat="ps -e -o pcpu,pid,cpu,nice,state,cputime,args --sort -pcpu | sed '/^ 0.0 /d'"
alias wylie='l=20; x=1300; y=100; d=-5;for i in `seq $x $d $y`; do beep -l $l -f $i; done'
beepwhenup () { echo 'Enter host you want to ping:'; read PHOST; if [[ "$PHOST" == "" ]]; then exit; fi; while true; do ping -c1 -W2 $PHOST 2>&1 >/dev/null; if [[ "$?" == "0" ]]; then for j in $(seq 1 4); do beep; done; ping -c1 $PHOST; break; fi; done; }
shopt -s checkwinsize
export PATH=${PATH}:/home/tommy/android-sdk-linux_86/tools
alias vimclean="find . -iname '*sw[po]' -print -delete"
howmuchmem () { PROCNAME="$@"; echo $PROCNAME IS USING $(echo "scale=4; ($(ps axo rss,comm|grep $PROCNAME| awk '{ TOTAL += $1 } END { print TOTAL }')/$(free | head -n 2 | tail -n 1 | awk '{ print $2 }'))*100"|bc)% of system RAM; };

updated Fri Mar 12 07:35:22 CST 2010

·

If you want to remove the first, let’s say, 27 characters from each line of output, you would:

$ some command|sed 's/^.\{27\}//'

· · ·

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh
 
# denyhosts-remove.sh
#
# AUTHOR: Tommy Butler, email: $ echo YWNlQHRvbW15YnV0bGVyLm1lCg==|base64 -d
# VERSION: 1.0
#
# SUMMARY:
# Use this script to Remove an IP address ban that has been errantly blacklisted
# by denyhosts - the ubiquitous and unforgiving brute-force attack protection
# service so often used on linux boxen.
#
# *Unlike the ruby equivalent somewhere out there on the net, this script
# actually works.
#
# INSTALL:
# Usage: Put this script somewhere in your $PATH, and execute it as root or
# with sudo.  Call it directly or with an IP address argument.  Multiple IP
# address arguments are not supported.  You'll need to `chmod +x` it first.
#
# LICENSE:
# GNU GPL 1.0
# Copyright 2009 Tommy Butler, All rights reserved
 
BASE_PATH="/var/lib/denyhosts";
IP=$1
 
if [[ "`/usr/bin/id -u`" != "0" ]]; then
	echo "Run this script as root or with sudo or app can't run correctly.  Aborted."
	exit 1;
fi
 
cd $BASE_PATH
 
if [[ "`pwd`" != "$BASE_PATH" ]]; then
	echo "Couldn't cd to $BASE_PATH.  Abort."
	exit 1;
fi
 
if [[ "$IP" == "" ]]; then
	echo "Enter the IP address you want to un-ban"
	read IP
fi
 
if [[ "$IP" == "" ]]; then
	echo "No IP address given.  Abort."
	exit 1;
fi
 
/etc/init.d/denyhosts stop
 
/usr/bin/perl -pi -e "s/^.*?$IP.*\n//g" /etc/hosts.deny *
 
/etc/init.d/denyhosts start
 
exit $?

· · · ·

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# AUTHOR:   Tommy Butler $ echo PGFjZUB0b21teWJ1dGxlci5tZT4K|base64
# DATE:     Tue Apr 28 11:39:28 CDT 2009
# VERSION:  1.0
# USAGE:    tweetpic "your tweet message here" "/path/to/image/file.jpg"
# PREREQ:   you need to have curl and gpg installed
 
# SUMMARY:
# Upload to twitpic and post to twitter in one go from the command line with
# this script  I wrote.  Prerequisites- gpg encrypt (with ascii-armor option)
# a text file with your  username and password, each  on its own line (\escape
# any spaces in your password); save the text file as ~/twitter-credentials.asc
# I guess if you can't figure out how to use gpg, ask someone who does or...
# RTFM: man gpg.
# PS - chmod 0600 your twitter-credentials file ;)
 
cd # start in homedir
 
# check if there's any input
if [[ "$1" == "" || "$2" == "" ]]; then
	cat <<usage
Usage:
`basename $0` "your tweet message here" "/path/to/image/file.jpg"
USAGE
	exit 1;
fi
 
# check if image exists
if [[ ! -e "$2" ]]; then
	echo "That file (\"$2\") doesn't exist.  Try again."
	exit 1;
fi
 
# check if ~/twitter-credentials.asc exists
if [[ ! -e "twitter-credentials.asc" ]]; then
	echo "Can't find ~/twitter-credentials.asc"
	exit 1;
fi
 
# best keep your gpg-agent running...
cred=( $( gpg -d twitter-credentials.asc 2>/dev/null ) )
 
# BAM!  Do it. Upload the photo to tweetpic and post the tweet.
/usr/bin/curl --form username="${cred[0]}" --form password="${cred[1]}" \
--form media="@$2" --form-string "message=$1" \
https://twitpic.com/api/uploadAndPost
 
exit $?
 
# BUGS: email bugs/patches to the email address provided on line 2

· · · · ·

Atrixnet is owned and operated by me, Tommy Butler. Sometimes I do contract networking/programming jobs. Contact me for my résumé

 

Atrixnet is
Atrixnet is Linux Powered! - click to visit www.linux.com
Wikipedia Affiliate Button