發表文章

目前顯示的是 11月, 2009的文章

程序監控

程序監控 下面script可以監控給定的程序(利用process的識別單字),亦可以將結果透過MAIL發送出來 #!/bin/bash ################################################################################# # # Author: simon su # Create Date: 2008/6/6 # Object: To show the PS array processes and can also mail alert for losing processes. # Usage: #  1. "psMonitor-sync.sh": to show all process status #  2. "psMonitor-sync.sh -m xxx@ooo.com ": to mail the monitor result to xxx # ################################################################################# usage(){ echo Usage: echo  1. psMonitor-sync.sh: to show all process status \(JobName...\) echo  2. psMonitor-sync.sh -m xxx@ooo.com: to mail the monitor result to xxx. echo  3. psMonitor-sync.sh -d \"JobName XXXX OOOO\" [-m xxx@ooo.com]: to using specific keyword as the monitor key. } if [ -n "$1" ] && [ "$1" == "--help" ]; then usage exit 0 fi MAIL_TMP=/tmp/mail-psMonitor.txt if [ -n "$1&qu

Clean directory (first segment) and file (second segment) of specific dir

Clean directory (first segment) and file (second segment) of specific dir [weblogic@pamesapp01 bin]$ cat cleanEpartsTmpFile.sh #!/bin/bash export KEEP_DAYS=3 export DIR=/opt/data/public/eparts/tmpfile/ echo Start to clean $DIR echo Befor House Keeping $DIR ... Total Files: `ls -l $DIR | wc -l` find $DIR -type d -mtime +$KEEP_DAYS -maxdepth 1 -print -exec rm -rf {} \; echo After House Keeping $DIR ... Total Files: `ls -l $DIR | wc -l` export DIR2=/opt/data/public/eparts/tmp/ echo Start to clean $DIR2 echo Befor House Keeping $DIR2 ... Total Files: `ls -l $DIR2 | wc -l` find $DIR2 -mtime +$KEEP_DAYS -print -exec rm -rf {} \; echo Befor House Keeping $DIR2 ... Total Files: `ls -l $DIR2 | wc -l` 說明: find指令的"-type d"可以指定查詢的唯folder "-mtime +2" 代表modify day超過兩天 "-maxdepth 1"代表往下查詢一個階層(因為rm掉folder的話,再往下查就會有ERROR,雖不影響動做,但很難看...)

置換檔案集合中某個文字

置換檔案集合中某個文字 Example for fl in *.txt; do mv $fl $fl.old sed 's/find/replace/g' $fl.old > $fl done Implement: 批次更改 for name in *.sh; do  mv $name $name.old; sed 's/PTW01/PTW03/g' $name.old > $name; done

Find Newest File

Find Newest File 此script是用於awstats蒐集http log時,Master主機需要到各主機蒐集 為了減少資料蒐集不到的問題,在各蒐集對向上面有執行此cron job來固定將 最新的log檔案複製一份到同目錄下的http-access.log檔案。 Master主機即可以透過SCP到各蒐集目的地主機抓取此檔案以加入分析。 #!/bin/bash # # Copy the last file to http-access.log for awstat analysis # name=`ls -t /usr/local/apache/logs/2*.log` FF=`echo $name | awk '{print $1}'` cp $FF /usr/local/apache/logs/http-access.log 應用: wlog 把該程式放到PATH中,即可以在任何一個目錄下面調用tail –f看weblogic的最新的LOG檔案 (所謂最新就是這個關鍵字做grep後得到的set中最新的一筆) 可以使用類似下面的方式來看log檔案,只要在後面指定關鍵字就可以了 wlog EHR Source of wlog #!/bin/bash DIR=/home/weblogic/appsdomain/logs/ name=`ls -t $DIR | grep $1` FF=`echo $name | awk '{print $1}'` tail -f $DIR/$FF New Enhance Version #!/bin/bash LOG_DIR=/home/weblogic/appsdomain/logs/ LOG_DIR_PF=/home/weblogic/pfdomain/logs/ showLog(){ name=`ls -t $2 | grep $1` if [ -n "$name" ] ; then         FF=`echo $name | awk '{print $1}'`         tail -f $2/$FF else         echo $1 not found in $2! fi } SHOW_LOG="&q

Shell計算功能

Shell計算功能 使用$((計算式)) #!/bin/bash echo -n "Enter number : " read n sd=0 # store number of digit nd=0 on=$n # store $n so that we can use it later # use while loop to caclulate the number of digit while [ $n -gt 0 ] do sd=$(( $n % 10 )) # get Remainder n=$(( $n / 10 )) nd=$(( $nd + 1)) # calculate all digit in a number till n is not zero done echo "Numnber of digit in a $on is $nd" 使用"計算式|bc" ( while [ $ != 'x' ] do echo "Welcome to calculator (x to quit)" echo "Enter the first operand: " read value1 echo "Enter an operator (+, -, *, /): " read operator echo "Enter the second operand: " read value2 if [ " $ operator " = " + " ] ; then answer=$(echo "scale=2;value1+value2" |bc); elif [ " $ operator " = " - " ] ; then answer=$(echo " scale=2;value1-value2" |bc); elif [ " $ operator " = " / " ] ; then answer=$(echo "scale=2;

Spring configure for JDBC or Connection Pool

Spring using JDBC configuration Spring的DB存取可以設定使用proxool pool或是jdbc driver manager的方式 DAO的設定部分都不用錯修改喔~~ 下面是driver manager跟proxool的設定部分(需擇一,因為定義的bean id是一樣的啦,而且同一個專案,用一個就夠啦...) [applicationContext.xml]     <!-- Using JDBC Connection (select one with "Using proxool connection pool") -->     <bean id="projectDataSource"         class="org.springframework.jdbc.datasource.DriverManagerDataSource">         <property name="driverClassName">             <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>         </property>         <property name="url">             <value>                 jdbc:microsoft:sqlserver://server_ip:1433;DatabaseName=dbname             </value>         </property>         <property name="username">             <value>username</value>         </property>         <property name="password"

jQuery操作iframe的parent window

範例: function setParentElement(pname, v){  jQuery(window.parent.document).find("#theForm input[name='" + pname + "']").val(v); }

我的好站鍊結

直式書寫的Java 2D http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/Demonstrateshowtodrawverticaltext.htm Sample of creating JPEG http://www.mail-archive.com/java2d-interest@capra.eng.sun.com/msg02730.html Sample of Java 2D http://www.apl.jhu.edu/~hall/java/Java2D-Tutorial.html#Java2D-Tutorial-Fonts 學習JavaFX http://javafx.com/learn/howto.jsp

Firefox not support ALT attribute

Firefox 無法顯示圖片替代文字(ALT) 把 滑鼠指標移到網頁圖片上,會出現一個小方框的工具提示,這叫做圖片替代顯示。 語法為 alt。這個語法原本的作用是在圖片無法顯示時,用來取代圖片的文字,但卻越來越多人把它當成工具提示,文字和圖片毫無關係,這樣一來,當圖片無法顯示 時,替代的文字便不足以表達圖片的含意。 因此 Mozilla 的開發團隊便決定不支援 alt 屬性(只有圖片顯示不出來時顯示 alt),變相避免網頁作者的誤用。 不過如果真要在 Mozilla 系列瀏覽器要顯示工具的話,有另外一個屬性可以使用:「 title 」。 <img src="圖片" alt="替代文字" title="工具提示" /> <img src="圖片" alt="替代文字" title="工具提示" /> 雖然 title 屬性不見得所有瀏覽器都支援,如有些會將其顯示在狀態列上,但使用 title 不論在 Firefox 或者 IE 上都可以正常顯示,相容性是比 alt 來的高,所以建議以後寫網頁時不妨再多增加一個 title 屬性試試!

Hibernate query by joined FK table column

如何使用Criteria查詢時,使用FK table中的欄位作條件? DetachedCriteria c = DetachedCriteria.forClass(Hr2UserEvent.class); //主table中的欄位查詢 c.add(Restrictions.eq("workId", workId)); //FK中的欄位查詢 c.createCriteria("hr2UserEventType").add(Restrictions.eq("eventId", eventId)); //這裡是使用jdbctemplate查詢,當然,也可以用hobernate session Collection collection = getHibernateTemplate().findByCriteria(c);

Replace & Translate Functions

REPLACE(expr, from_string, to_string) ... 將會置換"整個"from_string到"整個"to_string select replace('a1234bcd','123','xxx') from dual; result: axxx4bcd TRANSLATE(expr, from_string, to_string) ....將會置換from_string中字元到to_string中字元 select translate('a12bc34bcd','123','xxx') from dual; result: axxbcx4bcd