2012年4月27日 星期五

python 相關



******** python web framework
Python Web frameworks, Part 1: Develop for the Web with Django and Python

perl 各種呼叫外部程式的方式

參見

system() 會另開一個 shell

`` 會使用當下的 shell

exec() 是把當下的shell直接改成執行指定的指令

2012年4月25日 星期三

wsadmin - jython


啟動 wasadmin

/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/bin/wsadmin.sh -username ${username} -password ${password} -lang jython -profileName AppSrv01

執行 .py 檔案

/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/bin/wsadmin.sh -username ${username} -password ${password} -lang jython -profileName AppSrv01 -f ${FILE}

********** 可以用的 AdminObject


*AdminConfig provides an interface to the WAS configuration repository available under profile_root/config. All AdminConfig services are provided by the Deployment Manager (assuming you're connecting remotely); there is no dependency on node agents.

*AdminControl provides an interface to JMX managed beans (MBeans) in your WAS environment. In general, MBeans are only available for the resources that are running. For example, if an application server is down, the corresponding MBean will not be available.


**********列出所有 Server

import  java.lang.System  as  sys
lineSeparator = sys.getProperty('line.separator')
jdbcps=AdminConfig.list('Server').split(lineSeparator)
for server in jdbcps:
        print "====================================================="
        print server
        print  AdminConfig.showAttribute(server,'name')
        #print  AdminConfig.showall(server)
        print "====================================================="

**********儲存變更
 AdminConfig.save()

********** Sync 另外一個 Node
import  java.lang.System  as  sys

def getAnotherNode():
    lineSeparator = sys.getProperty('line.separator')
    nodes = AdminConfig.list('Node').split(lineSeparator)
    thisnode=AdminControl.getNode()
    for node in nodes:
        nodename = AdminConfig.showAttribute(node, 'name')
        #print "PROC "+nodename
        if(nodename != thisnode):
            #print "find "+nodename
            return nodename

nodename = getAnotherNode()
Sync1=AdminControl.completeObjectName("type=NodeSync,node="+nodename+",*")
print nodename
if Sync1 != "":
AdminControl.invoke(Sync1, 'sync')

AdminConfig.save()


******************* 在 jython 檔中引入另一個 jython 檔的方式
用 execfile('C:/temp/save.py') 引入另一個檔,然後 直接 call 另一個 jython 檔中的 function

** 用 python include  的方式的話,不涉及 AdminApp, AdminConfig, AdminControl, AdminTask 元件的部分都可以正常工作。但是被引入的檔案本身看不到這些元件,所以會吐這種東西出來

NameError: AdminConfig

** 用 import 的方式似乎會當成 java 檔 compilie 成 class ?

參考

*******************參考
ServerManagement command group for the AdminTask object
Configuring servers with scripting

2012年4月24日 星期二

Linux (Redhat / Fedora / CentOS) 更改 hostname 的方式

* 改 /etc/hosts
* 改 /ets/sysconfig/network
* 用 hostname ${NewName} 再改一次

2012年4月19日 星期四

CentOS 6 ,SSH 使用 Public Key 登入

ssh-keygen -t dsa
產生  DSA key pair

id_dsa  ( Private Key )
id_dsa.pub  ( Public Key )

cd ~/.ssh
cat id_dsa.pub > authorized_keys
cat id_dsa.pub > authorized_keys2

** .ssh 本身的權限

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys2

** 有 SELinux 的話
/sbin/restorecon -R -v /home/$ACCOUNT/.ssh

參見

下載  Private Key

-- XShell
import 進 Key Manager

-- Putty
使用 PUTTYGEN.EXE 匯入
再轉成 Putty 的格式

import -> private key
save private key -> 存成 Putty 能用的 ppk 格式
然後在 putty 中指定 ppk 位置


--------------
需要把 key 送去別台 server

ssh-copy-id -i ~/.ssh/id_dsa.pub USER@HOST

*這個 script 的方向是 送出去 而不是 拉過來
*預設是用 RSA Key . 所以 DSA Key 要自己用 -i 指定 key 位置
*預設走 port 22 , 如果有改 port 要改寫 Script
*CentOS 6 以後有這個指令可以用
---------------