Thursday 21 November 2013

s3cmd : A command line tools to work with the amazon s3

Some time we need to work with our "aws s3" bucket and need a command line tool to access amazon's s3 restful api. " s3cmd " one of the command that will help you working on this.

-> To install s3cmd at your ubuntu system:
sudo apt-get install s3cmd

Once you install your s3cmd you need to configure your system to have your access key and secrete key to work with your s3 bucket.

To configure your s3cmd having the config, run the following command:

s3cmd --configure

 You will be asked for the two keys, access key and secrete key
 
 NOTE: You use this key, whey you use the ec2-upload-bundle command.
























Tuesday 19 November 2013

sample_screenrc

startup_message off    # don't show start up message
autodetach on     # auto detach on exit
escape ^Xx     # change ctrl-a to ctrl-x


termcapinfo xterm* ti@:te@     # allow scrolling   [ Note: use * after xterm so that you can get scrolling for all the different screen ]
defscrollback        9000            # default: 100 # Set default lines of scrollback.
ignorecase on           # case insensitive search in scroll-back mode
bufferfile $HOME/.screen-exchange       # keep the buffer exchange file out of /tmp

# My status line
caption always "Screens: %{.bW}%-w%{.rW}%f%n %t%{-}%+w %=%{..G}  %{W}%Y-%m-%d %{W}%c %{g} %H"

sorendition "kg"        # makes screen messages stand out, black on green
altscreen on            # full-screen programs (less, Vim) should be cleared once quit
vbell off               # visual bells are hard to do right. screen's isn't good
defutf8 on              # allow utf characters

 hardstatus alwayslastline
 hardstatus string '%{= kw}[ %{= kb}%H%{= kw} ][%= %{= kw}%?%-Lw%?%{= kW}%n*%f %t%?%?%{= kw}%?%+Lw%?%?%= ][ %{r}%l%{w} ]%{w}[%{r} %d/%m/%y %C %A %{w}]%{w}'

Saturday 16 November 2013

Regular expressions matching - regex or regexp



Regular expressions matching:

/hello/ -> work hello should be there in the string

/^hello/ -> ^ mean, the match string should be in start
/hello$/ -> $ mean, the match string should be at the end

/hel+o/ -> + mean, once or more [ "helo", "hello", "helllllllo"] -> with one "l", or 2 "l" or multple "l"
/hel*o/ -> * mean, zero or more time. Almost same as above, with true for "heo" too. ]  -> [ "heo", "helo", "hello", "hellllllo" ]
/hel?o/ -> ? mean, zero or with only one. [ "heo" or "helo" only. ]. This will not match [ hello, hellllllo ]

/hello|goodbye/ -> either|or
/he..o/ -> . mean any character . [ hello, heazo ]
/\wello/ -> \w mean alphanmeric or _ (underscore)
/\bhello/ -> \b mean word boundary => space tab.


example of matching one of a email address:
/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/

Few more example of regex:

1. regex to grep the mac address:

egrep -io "([0-9A-F][0-9A-F]:)"{5}"[0-9A-F][0-9A-F]"

ifconfig | grep -i -P '([0-9A-F]{2}:){5}([0-9A-Fa-f][0-9A-F])'

-P for support of perl regex.

2. regex for ipaddress
ifconfig | egrep -o "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])"

3.
 hostname  | egrep "(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])"

Notes on Regex:

*) for i in {1..9}; do touch $i.html; done

*) for i in `ls |grep html| cut -d "." -f1`; do mv ${i}.html ${i}.htm; done

/[crnld]ope/ -> [...] mean range of chars => mean will match ["cope" "rope", "nope", "lope" and "dope"] but not aope.


cat log1 |egrep -o -e "(client|appserver/webapp)/.*/" | perl -pe 's|(client\|appserver/webapp)|mydir|'

cat log1 |egrep -o -e "(client|appserver/webapp)/.*/" | perl -pe 's/(client|appserver\/webapp)/patch12/'

*** The above one liner will grep the above regex from the log1 file and do a search and replace, where ever "client" is there or "(appserver/webapp)" is there to "mydir" . ***


External links:
http://www.cheatography.com/davechild/cheat-sheets/regular-expressions/
http://www.cs.tut.fi/~jkorpela/perl/regexp.html
http://ult-tex.net/info/perl/
http://cloud.github.com/downloads/tartley/python-regex-cheatsheet/cheatsheet.pdf
http://www.regular-expressions.info/
http://overapi.com/regex/