2013年3月6日 星期三

bash script 預設變數


  • $# :代表後接的參數『個數』,
  • $@ :代表『 "$1" "$2" "$3" "$4" 』之意,每個變數是獨立的(用雙引號括起來);
  • $* :代表『 "$1c$2c$3c$4" 』,其中 c 為分隔字元,預設為空白鍵, 所以本例中代表『 "$1 $2 $3 $4" 』之意。

Citrix vlan指令




vlan-create
vlan-create pif-uuid=<uuid_of_pif> vlan=<vlan_number> network-uuid=<uuid_of_network>

Create a new VLAN on a XenServer host.


pool-vlan-create
vlan-create pif-uuid=<uuid_of_pif> vlan=<vlan_number> network-uuid=<uuid_of_network>

Create a new VLAN on all hosts on a pool, by determining which interface (for example, eth0) the specified
network is on (on each host) and creating and plugging a new PIF object one each host accordingly.


vlan-destroy
vlan-destroy uuid=<uuid_of_pif_mapped_to_vlan>

Destroy a VLAN. Requires the UUID of the PIF that represents the VLAN.

tr -- translate or delete characters



http://linux.about.com/library/cmd/blcmdl1_tr.htm

NAME

tr - translate or delete characters  

SYNOPSIS

tr [OPTION]... SET1 [SET2]  

DESCRIPTION

Translate, squeeze, and/or delete characters from standard input, writing to standard output.
-c, --complement
first complement SET1
-d, --delete
delete characters in SET1, do not translate








Debian Intaller Preseeding



Debian-like OS auto installation

http://lackof.org/taggart/hacking/d-i_preseed/

2013年3月5日 星期二

python的super()深入研究


http://gcoder.blogbus.com/logs/42444130.html

http://blog.csdn.net/johnsonguo/article/details/585193

http://simba-wjxy.iteye.com/blog/669517


getopt vs getopts




http://blog.onetechnical.com/2012/07/16/bash-getopt-versus-getopts/

http://linuxwell.com/2011/07/14/getopt-in-bash/

getopts基礎使用



[Note that]

getopts is not able to parse GNU-style long options (--myoption) or
                                              XF86-style long options (-myoption)



How it works


  • In general you need to call getopts several times. 
  • Each time it will use "the next" positional parameter (and a possible argument), if parsable, and provide it to you. 
  • getopts will not change the positional parameter set — if you want to shift it, you have to do it manually after processing:
shift $((OPTIND-1))
# now do something with $@
Since getopts will set an exit status of FALSE when there's nothing left to parse, it's easy to use it in a while-loop:
while getopts ...; do
  ...
done
getopts will parse options and their possible arguments. It will stop parsing on the first non-option argument (a string that doesn't begin with a hyphen (-) that isn't an argument for any option infront of it). It will also stop parsing when it sees the -- (double-hyphen), which means end of options.


[getopts Base Syntax]

The base-syntax for getopts is:
getopts OPTSTRING VARNAME [ARGS...]
where:
OPTSTRINGtells getopts which options to expect and where to expect arguments (see below)
VARNAMEtells getopts which shell-variable to use for option reporting
ARGStells getopts to parse these optional words instead of the positional parameters

The option-string

  • The option-string tells getopts which options to expect and which of them must have an argument. 
  • The syntax is very simple — every option character is simply named as is, this example-string would tell getopts to look for -f, -A and -x:

getopts fAx VARNAME
  • When you want getopts to expect an argument for an option, just place a : (colon) after the proper option flag. 
  • If you want -A to expect an argument (i.e. to become -A SOMETHING) just do:

getopts fA:x VARNAME
  • If the very first character of the option-string is a : (colon), which normally would be nonsense because there's no option letter preceeding it, getopts switches to the mode "silent error reporting". In productive scripts, this is usually what you want (handle errors yourself and don't get disturbed by annoying messages).




[Used Variable]

OPTIND
     option index, Holds the index to the next argument to be processed.

  • This is how getopts "remembers" its own status between invocations. Also usefull to shift the positional parameters after processing with getopts
  • OPTIND is initially set to 1, and needs to be re-set to 1 if you want to parse anything again with getopts


OPTARG
      option argument, This variable is set to any argument for an option found by getopts.

  • It also contains the option flag of an unknown option.



OPTERR
      option error, (Values 0 or 1) Indicates if Bash should display error messages generated by the getopts builtin

  • The value is initialized to 1 on every shell startup - so be sure to always set it to 0 if you don't want to see annoying messages!



http://wiki.bash-hackers.org/howto/getopts_tutorial

MapReduce DistributedCache


How to use MapReduce DistributedCache v0.20.2

首先要先
import org.apache.hadoop.filecache.* ==> 給 DistributedCache用
import java.net.RUI
import org.apache.hadoop.fs.Path

2013年3月4日 星期一

Python的"方法(method)": 方法是物件(Method Object)

方法也是物件

在Python中,"類別方法(class method)"能經由"實例(instance)"或是"類別(class)"來存取操作。

基本上會有兩種的操作模式:

(1)
(2)




Python Inheritance(繼承)


  • 在Python中所有類別都繼承了object類別
  • Python支援"多重繼承"

2013年3月3日 星期日

Notepad++開啟多個視窗

Run => Open in another instance

git的物件型態

在物件儲存中,git僅使用了四種型態的物件:

1.  BLOBs, Binary Large OBjects (二進位的大型物件):
   
 檔案的每個版本都是由Blob所組成的。而這個詞彙被廣泛使用在資訊界,泛指可以儲存任何型態資料的檔案或變數,而且使用BLOBs的程式是並不會在意其內部結構的,因為BLOB型態的資料不易理解,因為它並沒有包含任何關於檔案的資訊,甚至檔案名稱都沒有。

2.  Tree:
     樹狀物件代表一個階層的目錄資訊。它記錄著
     I.  BLOB辨識碼
    II.  BLOB的路徑名稱
   III.  以及在這個目錄中所有檔案的一些資訊。

     樹狀物件本身也可以遞迴的參考其他子樹物件,然後建立出完整的檔案以及子目錄的階層架構。


3.  Commits(送交): 
---  送交物件擁有每次容器更動時的所有資訊,包含了作者、送交者、送交的時間以及歷史紀錄訊息等。

---  每次的送交都會指向一個樹狀物件,這個物件紀錄了送交當下該容器的狀態。(除了最一開始的送交沒有"父送交物件",而大多數的送交都會有一個"父送交物件")


4.  Tags(標籤):
     
標籤物件將人類易讀的名字賦予給特定物件(通常是Commits送交物件)


git的tag(標籤)

git tag的基礎概念


git目前僅有實作一種標籤物件,但它卻有兩種型態:


1. Lightweight Tag(輕量標籤):
   
輕量標籤參照至一個"送交物件",且通常是該容器所私有的標籤(?!),這種標籤不會在物件儲存上建立永久物件。 
2. Annotated Tag(標示標籤):
   
標示標籤則會真實的建立一個物件,而該物件裡面會包含你所提供的訊息,則該訊息可以根據RFC-4880使用GnuPG金鑰來簽屬"數位簽章"。



Git將Lightweight Tag以及Annotated



git tag的使用



http://blog.wu-boy.com/2010/11/git-%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6-%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%E6%A8%99%E7%B1%A4tag/

http://gitbook.liuhui998.com/3_7.html

git所維護的特殊符號參照



  • git當中所有的符號參照都可以使用 git symbolic-ref 指令來管理
  • git因為某些特殊目的所以維護了一些特別的符號參照,它們可以被用在任何可以使用"送交(commit)"的地方:
    1.  HEAD   
         HEAD永遠指向目前分支上最新的commit(送交)。當你修改分支時,HEAD就會被更新,指向該分支最新的commit(送交)。


    2.  ORIG_HEAD   
         在執行某些動作例如"merge(合併)"或是"reset(重設)"時,在執行之前,會將前一個版本的HEAD紀錄在ORIG_HEAD。
        可以使用ORIG_HEAD來回復至前一個版本或者是進行比較。


    3.  FETCH_HEAD
       
    當使用"遠端容器(Remote Repo)"時,git fetch指令會記錄從 .git/FETCH_HEAD檔案中所有分支的HEAD。
         FETCH_HEAD就是你抓取的上一個分支的HEAD,並且僅在抓取的指令之後有效。使用這個符號參照,你可以找到你使用 git fetch指令所抓取的HEAD,並且不用指定分支名稱。


    4.  MERGE_HEAD
        當合併在執行時,另一個分支的HEAD會被暫時的紀錄在MERGE_HEAD之中。
        換句話說:  MERGE_HEAD會指向要被合併到目前HEAD的送交物件。


    [Note]
           雖然可以使用上述的符號參照來建立自己的分支,但不建議這麼做!!

git中的檔案分類



Git將"檔案"分成三大類:
  1. 被追蹤(tracked): 
    被追蹤的檔案代表它已經在容器或是已經在索引中準備好了。
    EX: 要新增一個檔名叫做somefile的檔案此管理容器中,執行git add somefile即可。
  2. 被忽略(ignored):
    被忽略的檔案必須設定為"隱藏的"或是"被忽略的",就算檔案本身在你所管理的容器中。
    Git會維護一張被忽略的檔案清單(.gitignore),可以在你管理的容器內自行配置要忽略的檔案。
  3. 不被追蹤(untracked):
    不屬於前述兩個類別的檔案就稱之為"不被追蹤"的檔案。