2014年3月13日 星期四

shell 讀檔案 及檢查檔案是否存在


突然需要檢查一些檔案是否存在
很少在寫shell 因此紀錄如下


1.開啟一txt檔
2.一行一行檢查
3.每一行的前三字元 會決定其所在的資料夾
4.移到他的目錄檢查對應的檔案是否存在

#!/bin/bash
filename='/home/cdrs/temp/ilake/nomoj.txt'
exec < $filename  #執行打開檔案
while read line    #讀檔案內容
do
        #echo ${line:0:3}   取每一行的前三個字元
    cd /home/cdrs/backup/response/${line:0:3}/              #移到此目錄  
    if [ -e $line.pgp ];then                      #檢查此內容檔案是否存在
       echo $line exists >>/home/cdrs/temp/ilake/nomojcheck.txt
    else
       echo $line does not exist >> /home/cdrs/temp/ilake/nomojcheck.txt
     fi
done

2014年3月11日 星期二

rails ajax - do javascript after submit

碰到一個問題是
form submit 之後還需要執行一個javascript

本來很簡單的直接用
<%= simple_form_for [@goal ,@schedule] ,:html => { :id => 'event_form' }, :remote => true do |f| %>
<div>
<%= f.input :title %>
<%= f.input :description %>
<%= f.button :submit , :class => "btn btn-success" ,:onclick => "refetch_events_and_close_dialog()" %>
</div>
<% end %>
:remote => true  ajax
:onclick => "refetch_events_and_close_dialog()" submit後直接呼叫我要叫的javascript function
我的refetch_events_and_close_dialog 是要refresh 一些資料
剛好是這個submit更新完後的資料

但卻不可行refresh的資料還是舊的
我猜測大概是submit 和我onclick是同時的 所以導致我refresh的是還沒更新的資料

因此就改成
$(document).ready(function(){
  $('#desc_dialog').on('submit', "#event_form", function(event) {
    event.preventDefault();
    $.ajax({
      type: "POST",
      data: $(this).serialize(),
      url: $(this).attr('action'),
      success: refetch_events_and_close_dialog,
      error: handle_error
    });
    function handle_error(xhr) {
      alert(xhr.responseText);
    }
  });
});
$(document).ready就定義說#event_form這個如果submit的話
所觸發的function
用ajax成功後執行refetch_events_and_close_dialog

2014年3月8日 星期六

html object embed images

images

<img src="smiley.gif" alt="Smiley face" width="42" height="42" title="ilake">
alt 當圖片因為被刪掉或網路等問題 無法顯現時所會出現的文字 (alternate text)
title 當滑鼠指標移到圖片時 顯現的文字

object , embed



通常一起使用,為了要兼顧瀏覽器
因為之前IE 很多不支持embed 只支持object
參考連結

html dl dt dd



dl 的意義是 Definition List,中文是「定義清單
dt 的意義是 Definition Term,中文是「定義項目」。
dd 的意義是 Definition Description,中文是「定義描述」。


<dl>
  <dt>Coffee</dt>
  <dd>Black hot drink</dd>
  <dt>Milk</dt>
  <dd>White cold drink</dd>
</dl>

效果如下


Coffee
Black hot drink
Milk
White cold drink

2014年3月7日 星期五

html text


簡單的幾種html text tag的格式

<em>Emphasized text</em><br>
<strong>Strong text</strong><br>
<dfn>Definition term</dfn><br>
<code>A piece of computer code</code><br>
<samp>Sample output from a computer program</samp><br>
<kbd>Keyboard input</kbd><br>
<var>Variable</var><br>
<q>test</q><br>
<address>address<address><br>

效果如下


Emphasized text
Strong text
Definition term
A piece of computer code
Sample output from a computer program
Keyboard input
Variable
test
address

可以維持輸入的格式<pre></pre>
Text in a pre element               
is displayed in a fixed-width
font, and it preserves
both      spaces and
line breaks
Text in a pre element
is displayed in a fixed-width
font, and it preserves
both      spaces and
line breaks

<abbr title=“ilake”>  amy </abbr> ->滑鼠指標移過去時會顯示ilake

2014年3月6日 星期四

SCP和SFTP不用輸入密碼的公鑰方法



一.client端
  1.進入home目錄
     建立.ssh資料夾
# ll –a     查看有沒有.ssh
# mkdir .ssh  建立.ssh
  2.
#cd .ssh      進入.ssh
#ssh-keygen -t rsa  執行創建密鑰命令
3.
把.ssh目錄下的公鑰文件:/當前用户home目路/.ssh/id_rsa.pub文件傳輸到server上
#scp/home/ap/ilake/.ssh/id_rsa.pub ilake@28.192.141.129:/ilake/.ssh
#ssh-keygen 


二.server端

1.通過檢查home目錄的權限必須是755
2.
# cd /.ssh                      進入到.ssh目錄  .ssh權限必须是755或者700
# cp id_rsa.pub authorized_keys 第一次添加時將公鑰重命名為authorized_keys
# chmod 644 authorized_keys     公鑰文件的權限必须是644
如果有多個client,依次将client公鑰附加到server的authorized_keys文件内即可。

# cat /tmp/id_rsa.pub >> authorized_keys

測試時 直接輸入
# sftp ilake@ip    成功的話就可以直接登入
若只輸入sftp ip 則扔然要有密碼


來源 http://jingyan.baidu.com/article/e5c39bf56245ae39d7603331.html

Unix權限的基本概念


檔案的權限有三組,分別歸屬於Owner,Group,Everyone





















 755 就是代表:Owner可以讀寫執行(7)、Group只能讀取跟執行(5)、其他的人只能讀取跟執行(5)。


來源http://hiraku.tw/2010/03/227/