一月 26th, 2012 by admin
狀況描述:我人長時間在台北,有兩台機器在台南二十四小時不關機,但是放置的環境電力不穩定,會有跳電危險,以及一年一次的電力維修。我可能不知道電力維修,而讓電腦放著把飛瑞 A-500 的電力耗盡關機。
我找到 APC-MGE Back-UPS ES 500VA (BE500) 這台
http://shopping.pchome.com.tw/DCAD3Y-A37045887
目前設定在停電的時候大概會發生下面這樣的事情
1.停電
2.UPS 供電
3.並且在電力剩下 15% 的時候發出訊號使連結的電腦關機
4.再由外掛的設備(例如電風扇)將 UPS 電力耗盡
5.UPS關機
6.市電復電,UPS開機
7.主機板偵測到電力,開機
或者
4.UPS 電力尚有殘存
5.市電復電,UPS 恢復充電
6.主機板設定每天晚上七點半由主機板上的時鐘發出 wake up 訊號開機
總而言之,無論是什麼情況,現在電腦都可以在二十四小時內開機了
哈哈
我的作業系統是:Ubuntu10.04.3 LTS Server
安裝了 apcupsd 這套 apc 的軟體來偵測 UPS 發出的關機訊號
UPS 上面有 RJ54 的網路孔,可以用買 UPS 裡面附贈的 RJ54-USB 線進行連結
這樣 UPS 才可以叫電腦關機
我將 UPS 市電拔掉實測過關機,看起來就像是 UPS 發出 sudo shutdwon -h now 將電腦關機的感覺
實際上下什麼指令關機的要去看原始碼才知道了
一月 11th, 2012 by admin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| lftp ftp://xxx:162938@xxx.xxx.xxx.xxx
lftp owen@xxx.xxx.xxx.xxx:~> mirror --reverse --delete prebuilt
Total: 1907 directories, 15044 files, 8338 symlinks
New: 15044 files, 0 symlinks
2025750448 bytes transferred in 325 seconds (5.94M/s)
lftp owen@owen1.twbbs.org:~>
time lftp -c "open ftp://xxx:162938@xxx.xxx.xxx.xxx;mirror --reverse --delete prebuilt"
real 1m26.084s
user 0m42.390s
sys 0m1.710s
sent 2027701117 bytes received 318489 bytes 11555667.27 bytes/sec
total size is 2026376344 speedup is 1.00
real 2m55.261s
user 1m7.540s
sys 0m14.040s
time rsync -av -e ssh prebuilt/ xxx@xxx.xxx.xxx.xxx:/home/xxx/prebuilt/
sending incremental file list
sent 1037166 bytes received 1918 bytes 692722.67 bytes/sec
total size is 2026376344 speedup is 1950.16
real 0m0.753s
user 0m0.120s
sys 0m0.100s |
結果相差非常懸殊
要傳輸的資料夾大小 2G
lftp mirror 傳輸整個資料夾 325 秒,再傳輸一次做相同比對的測試 86 秒
rsync 走 ssh 傳輸只個資料夾 175 秒,再傳輸一次做相同比對的測試 0.75 秒
這比對的速度也太快了= =a
一月 6th, 2012 by admin
當我們用 php 的 exec 指令,想要叫電腦執行某些指令或者 shell script 時候
可能會遇到問題
因為 exce 使用 /bin/sh 作為執行的環境,而 linux 有可能使用 /bin/sh -> /bin/dash 當作 /bin/sh 來使用
而 dash 沒有 source 這種 shell command,bash 才有。
這是第一個問題
第二個問題:當我rm /bin/sh;sudo ln -s /bin/bash /bin/sh
看起來應該可以讓我的 php 的 exec() 使用 bash 作為執行環境了
但是為什麼動作的結果和我自己在登入電腦之後在 bash 環境下執行的結果不一樣?
例如 source .bashrc ,顯示 file not found
在 sh 的情況下是因為在 PATH 裡面搜尋不到檔案的話, sh 不會到當前目錄再進行搜尋
但是 bash 在 PATH 裡面搜尋不到檔案的話, bash 是會到當前目錄進行搜尋的
BUT,當我把 /bin/sh -> /bin/bash 之後,用 exec 呼叫,他似乎不是這樣運作…what the fuxx …
解法:
1
| exec("/bin/bash -c\"source .bashrc\" "); |
這樣,我解決了我的問題。但我依然不知道 exec 執行的時候用 bash 跟我帳號登入機器執行 bash 為什麼會不一樣!
一月 5th, 2012 by admin
下面是我貼在 stackoverflow.com 發問的問題,後來我自己解掉了。
http://stackoverflow.com/questions/8737234/how-php-nusoap-client-transfer-complextype-to-net-soap-server
不想翻譯了…
總之,如果你有「使用 php 傳送 ComplexType 型態的參數到 web service 的需求」的話,那就花個半小時看一下這篇吧
I am trying to create a client soap call using php nusoap to an existing SOAP server build on .NET that contains complexTypes.
I want to call QueryTestCategory(see belows)
And it has param searchTag and Call_Result that are string
But param LGI is type of LoginInfo(struct LoginInfo { string User_Name; string Password; })
So,how do I setup the parameters for QueryTestCategory?
I perform a getTypes I receive the following
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| struct HelloWorld { }
struct HelloWorldResponse { string HelloWorldResult; }
struct QueryTestSuite { LoginInfo LGI; string searchTag; string Call_Result; }
struct LoginInfo { string User_Name; string Password; }
struct QueryTestSuiteResponse { ArrayOfSuiteInfo QueryTestSuiteResult; string Call_Result; }
struct ArrayOfSuiteInfo { SuiteInfo SuiteInfo; }
struct SuiteInfo { string Test_Suite_ID; string Test_Suite_Name; string Tag; string Owner; string Remark; }
struct QueryTestCategory { LoginInfo LGI; string searchTag; string Call_Result; }
struct QueryTestCategoryResponse { ArrayOfCategoryInfo QueryTestCategoryResult; string Call_Result; }
struct ArrayOfCategoryInfo { CategoryInfo CategoryInfo; }
struct CategoryInfo { string Test_Category_ID; string Test_Category_Name; string Tag; string Owner; string Remark; }
struct QueryTestCase { LoginInfo LGI; string searchTag; string Call_Result; }
struct QueryTestCaseResponse { ArrayOfTestCaseInfo QueryTestCaseResult; string Call_Result; }
struct ArrayOfTestCaseInfo { TestCaseInfo TestCaseInfo; }
struct TestCaseInfo { string Test_Case_ID; string Test_Case_Name; string Test_Case_Version; string Tag; string Entry_Point; string Test_Kit_Name; string Test_Kit_Version; string Extra_Parameter; string Estimate_Time; string Function_Team; string Remark; string Test_Log_Parser_Name; string Test_Log_Parser_Version; string Test_Log_Parser_Entry_Point; string Test_Log_Parser_Extra_Parameter; string Owner; }
struct QueryTestResult { LoginInfo LGI; string TaskID; string Call_Result; }
struct QueryTestResultResponse { string QueryTestResultResult; string Call_Result; } |
I try this, but it fails
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
| /*
* $Id: wsdlclient1.php,v 1.3 2007/11/06 14:48:48 snichol Exp $
*
* WSDL client sample.
*
* Service: WSDL
* Payload: document/literal
* Transport: http
* Authentication: none
*/
require_once('lib/nusoap.php');
$proxyhost = isset($_POST['proxyhost']) ? $_POST['proxyhost'] : '';
$proxyport = isset($_POST['proxyport']) ? $_POST['proxyport'] : '';
$proxyusername = isset($_POST['proxyusername']) ? $_POST['proxyusername'] : '';
$proxypassword = isset($_POST['proxypassword']) ? $_POST['proxypassword'] : '';
$client = new nusoap_client('http://www.example.com/Query.asmx?WSDL', 'wsdl',
$proxyhost, $proxyport, $proxyusername, $proxypassword);
$err = $client->getError();
if ($err) {
echo "Constructor error";
}
// Doc/lit parameters get wrapped
$param = array('User_Name' => 'SSD_WS_01', 'Password' => 'SSD_WS_01', 'searchTag' => 'test', 'Call_Result' => '');
$result = $client->call('QueryTestCategory', array('parameter' => $param), '', '', false, true);
// Check for a fault
if ($client->fault) {
print_r($result);
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo 'Error;
} else {
// Display the result
echo 'Result';
print_r($result);
}
} |
I found ANSWER!
After reading this web page and many many other information
http://gznofeng.iteye.com/blog/951762
My finally code is like below
To sum up…
create $param1 = new stdClass,set parameter via $param1->varName = ’something’
That all!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| 23 // Doc/lit parameters get wrapped
24 //$param1 = array('User_Name' => 'SSD_WS_01', 'Password' => 'SSD_WS_01');
25 $param1 = new stdClass();
26 $param1->User_Name = 'SSD_WS_01';
27 $param1->Password = 'SSD_WS_01';
28
29 $result = $client->call('QueryTestCategory', array('LGI' => $param1, 'searchTag' => '' ), '', '', false, true);
30 // Check for a fault
31 if ($client->fault) {
32 echo '<h2>Fault</h2>';
33 print_r($result);
34
35 } else {
36 // Check for errors
37 $err = $client->getError();
38 if ($err) {
39 // Display the error
40 echo '<h2>Error</h2>' . $err;
41 } else {
42 // Display the result
43 echo '<h2>WoW,Result</h2>';
44 print_r($result);
45
46 }
47 } |