2011年5月29日 星期日

[ linux ] date

在 linux 下,要碰到時間相關的事情~
就不得不用到內建的程式  data
下面來介紹幾個常常用到的功能……


date
輸出系統時間。


date +%s
輸出unix 時間
是從 utc 時間  1970/01/01 00:00:00 起~到現在的總秒數~

如果要自訂輸出時間的格式~
date +"%Y/%m/%d %Z %H:%M:%S"
2011/05/29 UTC 15:08:16


%Y   年
%m   月
%d    日
%Z    時區
%H    小時
%M   分鐘
%S    秒

後面的 小時、分、秒 都是大寫~ 這樣可以跟 月份的 m 做區分,蠻好記的。
如果忘記的話,可以直接 date --help
裡面會有更多細部的參數可以用~~~


再來是查詢時間的用法~~
date -d ' -2 day'
在 -d 這個 option後接上要查的時間
例子是兩天前,也可以有其它的間隔~~ 
像是  hour week year 都可以~~

打數字也OK,它的接受度出乎我的意料:p

date -d ' 2011/11/11 UTC 12:12:12'
Fri Nov 11 12:12:12 UTC 2011

這時候會想說為什麼要打數字…? 因為,它可以用在時間格式的轉換~
在做一些監控的 service 時,直接把時間統一指定成 UTC 時間的  unix 格式是很方便的!
可以開個變數 ~
WhatTime=`date -u +%s`
echo $WhatTime
( -u 是指定時區為  UTC )

那如果是從其它軟體、系統下載入的時間,也可以寫個 bash 呼叫  date來做格式轉換~
date -d ' 2011/11/11 UTC 12:12:12' +%s
1321013532
只要再後面補個 + 再打上自己想要的輸出格式~~

date  常用的功能也介紹差不多了~~

下面要不忘提醒一下,校正時間相關的指令
在爽爽的使用這些系統時間時,如果沒有把時間同步做好的話
收集到的數據可信度就會下降啦!!

對時用的軟體  ntpdate
可以直接手動執行校時動作
ntpdate <校時網址>

台灣的有下面幾個可以用~~~  (在 時間標準局 網站上可以查得到)
tock.stdtime.gov.tw
watch.stdtime.gov.tw
time.stdtime.gov.tw
clock.stdtime.gov.tw 
tick.stdtime.gov.tw

之後,可以把對時動作寫進 crontab 裡,讓系統每天自動幫你對時~~
vim /etc/crontab
加入下面這一行 
10 5 * * * root /usr/sbin/ntpdate tock.stdtime.gov.tw  &> /dev/null
( 對時的時間是 每天的 5 點10 分,如果要改成早上四點可以寫成…
10 4 * * * root /usr/sbin/ntpdate tock.stdtime.gov.tw  &> /dev/null


下面補個快速查詢表^ ^

date

date +%s

date +"%Y/%m/%d %Z %H:%M:%S"
2011/05/29 UTC 15:08:16

%Y   年
%m   月
%d    日
%Z    時區
%H    小時
%M   分鐘
%S    秒

#hour week year 
date -d ' -2 day'

date -d ' 2011/11/11 UTC 12:12:12'
Fri Nov 11 12:12:12 UTC 2011

WhatTime=`date -u +%s`
echo $WhatTime
( -u 是指定時區為  UTC )

date -d ' 2011/11/11 UTC 12:12:12' +%s
1321013532
只要再後面補個 + 再打上自己想要的輸出格式~~

ntpdate <校時網址>



2011年5月25日 星期三

Define some search engine about EGI grid operation on chrome

Add there link on   Tool> Option >Search engine manager

Some web page we'll frequently to use... like EGI GUSS ticket system, GOCDB, ROCNagios, bababa... ...
I define some engine as below.

engine Des.       Keyword        engine_link
GGUS                    ggus                  https://gus.fzk.de/ws/ticket_info.php?ticket=%s

Twiki_cern            cernsearch      https://cernsearch.web.cern.ch/cernsearch/Twiki.aspx?query=%s&scope=EGEE
GOCDB                 gocdb             https://gocdb4.esc.rl.ac.uk/portal/index.php?Page_Type=Submit_Search&Search_String=%s
RocNAGIOS          rocnagios        https://rocnagios.grid.sinica.edu.tw/nagios/cgi-bin/status.cgi?hostgroup=site-%s&style=overview
RocNAGIOS_host   rocnagiosh      https://rocnagios.grid.sinica.edu.tw/nagios/cgi-bin/status.cgi?host=%s
glite-APEL              apel                http://goc-accounting.grid-support.ac.uk/rss/%s_Sync.html





GGUS
When you want to open the ticket #00000
Then you can type only "ggus<tab>00000" Then open the ticket page.

GOCDB
GOCDB save the site page no any site information on the link.
Some time we need to find service or site on GOCDB.
Only can use there search engine.
Now, add the search into chrome.

RocNAGIOS (for APROC)
type the sitename to link your site service status page.

RocNAGIOS (for APROC)
type the service name

glite-APEL
type your site name to open the accounting data publish status about your site.


------------------------------------------------------------------------------
GGUS update the link......
GGUS                    ggus                  https://ggus.eu/ws/ticket_info.php?ticket=%s

XOR 運算子

Xor 運算子

在 C++ 裡面是用   ^  或是  XOR
兩變數相互作位元的羅輯互斥運算。

用個例子來介紹一下它的運算
A     0 1 0 1 1
B     0 0 0 1 0
----------------------------   A, B 分別是表示某個二進位的數字
C     0 1 0 0 1

C=A^B

由上面可以簡單看出,如果是 0 0 的組合得出來還是 0
如果是 1 0  就是 1
1 1 則得出 0

有幾個特別的情況~~
1. 任何數對零作用都是自己。
A  1 0 1 1
B  0 0 0 0
-------------
    1 0 1 1   = A
2. 自己對自己作用變成零。
A 1 1 1 0
B 1 1 1 0
-------------
   0 0 0 0 = 0

3. 照順序做下面三個指向完,A B 的值就對換了。
A = A ^ B
B = A ^ B
A = A ^ B


★ 這個算子的特性可以用做一些 mapping 、 換位的動作。


我會發現這個有趣的算子是在跟同事討論一個測網路流量的軟體中發現的~
程式的運作原理是指定一塊空間的資料,然後用 MPI 的function 讓它在 nodes 間互相copy。
那這時候,它必需要指定copy 檔案到除了source 端以外的其它node。
這時候就可以用上這個算子了。

把自己 rank 的編號當成 A 依度對 B( 0<B< max ) 作用。
就可以得出目的地了 ( max - 1 個)

int pair(int np,int p,int k)
{
    int q;
    q = p^k;
    if(q>np-1)
       return(-1);
    else
      return(q);
}



總覺得這種算子應該還有一些其它用途~
改天有聽到,再補充吧~~~