rsync + ssh 使用不同 port 執行

參考網址:Tsung's Blog
 

rsync + ssh 使用不同 port 的話, 需要加上 -e "ssh -p port_number", ex: 假設遠端的 ssh 機器是用 1234 port, 指令會如下述:

  • rsync -e "ssh -p 1234" -avz –bwlimit=3000 REMOTE_HOST:data_path .

另一種使用 –rsh='ssh -pPORT_NUMBER', 如下述範例:

  • rsync –rsh='ssh -p1234' -avz –bwlimit=3000 REMOTE_HOST:data_path .

另外一個是透過 .ssh/config, 做 ssh 遠端機器的相關設定, 如下述範例:

  1. vim .ssh/config
    Host REMOTE_HOST # 這個可以寫簡寫, 但是下面 rsync 的REMOTE_HOST 需與此一致.
    HostName REMOTE_HOST
    User YOUR_USERNAME
    Port 1234
    IdentityFile /home/YOUR_USERNAME/.ssh/id_rsa # 如果有在寫, 沒有這行可跳過不寫
  2. rsync -avz –bwlimit=3000 REMOTE_HOST:data_path . # 這邊就可以直接 rsync 即可.

 

發表於 Linux系統 | 發表迴響

SSH 免密碼登入

參考網址:dywang

  1. 在定時備份或批次遠端處理,往往需要免密碼登入遠端主機工作。為達此目的,首先必須在 client 端產生一組 key,包含公開金鑰(Public Key)與私密金鑰(Private Key),將公鑰送到要登入的主機,相互對應做免密碼的登入。key 的產生:

     

    [root@kvm8 ~]# ssh-keygen 
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa): 
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /root/.ssh/id_rsa.
    Your public key has been saved in /root/.ssh/id_rsa.pub.
    The key fingerprint is:
    c3:e9:25:65:00:c8:65:cb:e8:fe:4e:7e:ce:06:a4:9d root@kvm8.deyu.wang
    The key's randomart image is:
    +--[ RSA 2048]----+
    |   . o+..        |
    |    o+ . .       |
    |    . o   o      |
    |   .  .. +       |
    |    .+ .S .      |
    |   .. E. +       |
    |    . ...        |
    |     + .o        |
    |     .++o        |
    +-----------------+
    
  2. 將公開金鑰放到要登入的主機

     

    [root@kvm8 ~]# scp .ssh/id_rsa.pub kvm7.deyu.wang:.ssh/
    The authenticity of host 'kvm7.deyu.wang (192.168.122.7)' can't be established.
    RSA key fingerprint is 33:76:31:62:25:dd:eb:a6:1f:5a:54:10:b8:25:c3:66.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added 'kvm7.deyu.wang,192.168.122.7' (RSA) to the list of known hosts.
    root@kvm7.deyu.wang's password: 
    id_rsa.pub                                    100%  401     0.4KB/s   00:00  
    
  3. ssh 登入欲免密碼登入的主機,這時還是要密碼。

     

    [root@kvm8 ~]# ssh kvm7.deyu.wang
    root@kvm7.deyu.wang's password: 
    Last login: Tue Feb  4 19:31:13 2014 from 192.168.122.1
    
  4. 系統預設處理放置公鑰的檔案為 authorized_keys,所以必須把剛剛傳送過來的公鑰累加到這個檔案中:

     

    [root@kvm7 ~]# cat .ssh/id_rsa.pub >> .ssh/authorized_keys
    
  5. 特別注意目錄 .ssh 及檔案 authorized_keys 的權限,若群組或其他人的權限過大,除了安全性有問題外,也有可能因 ssh 判斷要對應的金鑰不安全,而無法對應,也就是不能免密碼登入。

     

    [root@kvm7 ~]# chmod 700 .ssh/
    [root@kvm7 ~]# chmod 644 .ssh/authorized_keys 
    [root@kvm7 ~]# ll -d .ssh 
    drwx------. 2 root root 4096 Feb  4 19:36 .ssh
    [root@kvm7 ~]# ll .ssh/authorized_keys 
    -rw-r--r--. 1 root root 401 Feb  4 19:36 .ssh/authorized_keys
    
  6. 退出 kvm7.deyu.wang 回到 kvm8.deyu.wang。

     

    [root@kvm7 ~]# exit
    logout
    Connection to kvm7.deyu.wang closed.
    
  7. 再次登入 kvm7.deyu.wang 已不需要密碼。

     

    [root@kvm8 ~]# ssh kvm7.deyu.wang
    Last login: Tue Feb  4 19:32:57 2014 from 192.168.122.1

實作對應(含不同的ssh port)
 

ssh-keygen #passphrase直接按enter
scp -P xxxx .ssh/id_rsa.pub 120.116.xx.xxx:.ssh/
ssh -p xxxx 120.116.xx.xxx
cat .ssh/id_rsa.pub >> .ssh/authorized_keys
chmod 700 .ssh/
chmod 644 .ssh/authorized_keys
exit #退出遠端主機
ssh -p xxxx 120.116.xx.xxx #已不需密碼 

 

發表於 Linux系統 | 發表迴響

ajax入門

參考網址:中興大學資管系

jquery

發表於 程式設計 | 發表迴響

拖曳排序

參考網址:

MIS腳印 JavaScript 表格拖放排序 AJAX 資料庫 for PHP 
在FireFox中會有問題,解決方法:
參考網址:Mozilla    Drag and Drop: Copy and Move elements with DataTransfer
javascript中加入function dragstart_handler(ev) 
另外在被拖曳的元素上除了draggable="true"還需加上ondragstart="dragstart_handler(event);"
不加ondragstart在firefox中無法拖曳。
例<tr class="data" draggable="true" ondragstart="dragstart_handler(event);">
目前還有一個問題未解決??(107.11.106更新,關掉手勢擴展就解決了。)
在firefox中拖曳太遠會開啟一個新視窗https://www.google.com/webhp

function dragstart_handler(ev) {
 console.log("dragStart");
 // Change the source element's background color to signify drag has started
//// ev.currentTarget.style.border = "dashed";
 // Add the id of the drag source element to the drag data payload so
 // it is available when the drop event is fired
ev.dataTransfer.setData("text", ev.target.id);
 // Tell the browser both copy and move are possible
ev.effectAllowed = "copyMove";
}

 

107.11.10更新:
firefox 下使用html5拖拽会自动打开新标签的解决办法 (這個方法無效)

另一篇文章:
使用draggable拖动一个图片时,火狐上总会新开一个窗口 (BINGO)
是不是安装了手势操作扩展?拖拽时会在新标签页中打开页面,在工具—附加组件里查看下已经安装的扩展。

 

CSDN h5拖拽在兼容火狐与IE的实现需要注意的事

發表於 程式設計 | 發表迴響

UltraEdit調校

UltraEdit中文網站

UltraEdit一直是我寫PHP程式時的最愛,之前用的是V18。使用時在顯示函式清單時速度很僈,所以就找新的版本試試。果然在V25中函示清單功能是正常的。新的版本又提昇了不少功能,也引入了主題的概念,試著做一些調校,符合自己的使用習慣。
畫面一開始會有個歡迎畫面,這是主要的調校功能所在,如果不小心關掉了,可以從「 說明」==> 「歡迎頁面」重新叫出來。
1) 主題:之前習慣用classic,試著改用Charcoal,有不同的Fu。(Charcoal選取文字時不明顯,改用Slate。)
2) 版面配置:選擇「多視窗」
3) Ribbon 或功能表/工具列:選擇「功能表/工具列」
4) 幾種設定

  • 備份:選擇不備份
  • 縮排尺寸:4 插入空格

再從功能表中「檢視」==>「 檢視/清單」==>取消「文件地圖」勾選。

範本:進階  顯示/修改範本 選php
 

foreach ($[+arr+] as $[+key+] ==> $[+value+]) {
 	^ // loop through values 
}

 

發表於 程式設計 | 發表迴響

smarty 與 adodb 使用範例

//smarty
{{php}}
$i++ ;
echo $i ;
{{/php}}

//smarty
{{include file='join2/tnc_gov_join_inc.htm' }} 

//smarty
{{ if  (! $list.have_game) }}
{{/if}}

//smarty
{{ if  (! $list.have_game) }}
{{else }}
{{/if}}

//smarty 註解
{{*   *}}

 

//php
// 取得參賽項目部份名冊資料replay
 $sqlstr = " select game_id , player_id ,play_group_id ,play_item_id ,class_ename,coach_id , reference , reference2 , reference_unit ,term_num ,term_spe_id
             from game 
             where  gov_code = '$_SESSION[session_log_id]'   order by play_group_id ,class_ename , term_num,player_id " ;
 $recordSet = $CONN->Execute($sqlstr) ;
 while ($row = $recordSet->FetchRow() ) {
   $id = $row['player_id'] ;    
   $game_list[$id][] =  $row  ;
   
   //以組別做呈現
   $play_group_id = $row['play_group_id'] ;    
   $play_item_id = $row['play_item_id'] ;   
   $player_id  = $row['player_id'] ; 
   $class_ename  = $row['class_ename'] ; 
   $row['player_sex'] =  $user_list[$player_id]['player_sex'] ;
   $row['player_name'] =  $user_list[$player_id]['player_name'] ;
   
   $game_list2[$class_ename][$play_group_id][] = $row ;
   $user_list[$player_id]['have_game'] = $play_group_id ;   //已參加的組別代號
 }

//smarty    
//陣列由前向後解開    
{{foreach  key=class_key item=group_data   from=$game_list2 }}
    {{foreach  key=group_key item=group_list   from=$group_data}}
        {{php}}
        $i=0 ;
        {{/php}} 
<table class =datatable width=100%>

    <caption>組別:{{$play_group_name.name[$group_key]}}{{$class_key}}</caption>
    <tr>
        <th>序號</th>  
        <th>姓名</th>
	    <th>性別</th>
    </tr>
        <!-- 項目 -->
        {{foreach key=user_key item=user_list from=$group_list }}
	     <!-- 同項目多人 -->
         <!-- 指定狀態 -->
    <tr>
        <td>
            {{php}}
            $i++ ;
            echo $i ;
            {{/php}}   
        </td>
        <td nowrap> {{$user_list.player_name}}</td>
	    <td>{{$sex[$user_list.player_sex]}}</td>	
    </tr>

        {{/foreach }} 
    {{/foreach }} 
    </table>
    <br>

{{/foreach }}

 

//php
$sqlstr = " select play_group_level   from gov  where played ='1' group by play_group_level  order by play_group_level  ";
$recordSet = $CONN->Execute($sqlstr);
while ($row = @$recordSet->FetchRow() ) {
   $play_group_level_id  = $row['play_group_level'] ;
   $level_name[$play_group_level_id] = $row['play_group_level']  ;
} 

//smarty
<form name="form1" method="post" action="sum_level_user_list.php">
  <select name="level_id" onChange="submit();">
    {{html_options options=$level_name  selected=$level_id }}
  </select>
</form>

 

//php
 $sqlstr = " select gov.gov_code ,gov.play_group_level ,gov.gov_name , count(*) as cc from player  ,gov 
             where   player.gov_code = gov.gov_code and gov.played='1'  and gov.play_group_level= '$_GET[level_id]'
             group by gov.gov_code  
             order by gov.gov_code    " ;
             
 $recordSet = $CONN->Execute($sqlstr);
 while ($row = @$recordSet->FetchRow() ) {
    $gov_list[$row['gov_code']] = $row['gov_name']  ;
}

//smarty
{{foreach  key=key1 item=list   from=$gov_list }}  
  <tr> 
    <td>{{$gov_list[$key1]}}</td>
    <td>{{$user_array[$key1][1]}}</td>
  </tr>
{{/foreach}}

ADODB
 

$recordSet = &$conn->Execute('select * from products');
if (!$recordSet) 
        print $conn->ErrorMsg();
else
while (!$recordSet->EOF) {
        print $recordSet->fields[0].' '.$recordSet->fields[1].'<BR>';
        $recordSet->MoveNext();
}

GetRow($sql)

FetchRow()
返回目前記錄內容的陣列,如果是檔尾(EOF),返回 false 。注意:不要把 FetchRow 和 MoveNext() 混用。

$CONN->Execute($sqlstr) or die ( $sqlstr ) ;

 

發表於 程式設計 | 發表迴響

DreamWeaver之MM_validateForm表單輸入檢查

參考網址:TechRepublic

在DreamWeaver中先設計好表單
視窗-標籤檢測器(或按F9)
在右方會出現「行為」標籤
按「+」選檢驗表單

發表於 程式設計 | 發表迴響

ADODB 手冊

參考網址:掃文資訊

發表於 程式設計 | 發表迴響

HTML5新屬性自動檢核表單與欄位格式是否填寫正確

參考網址:梅問題
參考網址:The art of web
參考網址:w3cplus pattern–HTML5的表单验证属性

表單驗證是件相當麻煩的事,除了要驗證欄位是否有填寫外,還要針對填入的資料格式是否正確,光是一個表單驗證,就相當的傷神,因此很早之前,也曾分享過一些驗表單的javascript套件,來解決這惱人的問題,但現在透過HTML5所提供的新屬性後,完全不用寫任何的程式,就可實現表單的驗證。

甚至還可審核資料格的是否正確,像是Email、網址、電話…..等,因此有表單驗證需求的朋友,現在也一塊來看看HTML5的個表單驗證要如何使用,與格式驗證的設定。

用法很簡單,只需在input的標籤加入「required」

<input name="text" id="text" type="text" required />

加入後,當未填寫就按送出時,就會跳出提示框。

當要驗證Email格式時,將type設為「email」,若是網址就為「url」

<input name="email" id="email" type="email" required />

除了驗證email與網址外,電話也是很重要的,由於電話編碼每個國家都不同,因此就不能透過type來作設定,而是用pattern這屬性,再加入正規表示法來作驗證,以手機來說,前四碼為電信商,後六碼為個人碼,所以可以這樣子寫 pattern='\d{4}[\-]\d{6}',這表示前方四碼輸入完後,需加入-隔開,再輸入六碼,這樣格式才正確。

<input name="mobile" id="mobile" pattern='\d{4}[\-]\d{6}' required />

若是室內電話時,再將pattern='\d{4}[\-]\d{6}'變成pattern='\d{2}[\-]\d{8}',這樣就大功告成了,是不是超EZ的呀!!且完全不用寫到任何的程式。

而這麼方便的功能,目前只有Safari不支援,其它的瀏覽器皆可正常運行。

 

發表於 程式設計 | 發表迴響

正規表示式語法測試及程式產生器

參考網址:https://regex101.com

說明文件
https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Guide/Regular_Expressions

發表於 程式設計 | 發表迴響