Saturday, October 02, 2010

SparkleShare

上一篇介紹過Dropbox,今天又發現到一套可以讓使用者自己架設線上備份與同步檔案的opensource project: SparkleShare,目前雖然還在Beta階段,不過我想應該很快就會有official了!

若公司內部,有這麼一台遠端檔案集中Server,其功能又與Dropbox類似的話,那就非常方便了!

Wednesday, September 29, 2010

Install Dropbox in OpenSUSE 11.3

今天無意間找到了一個非常實用的工具Dropbox,什麼是Dropbox?簡單的來說它是一個線上備份與檔案同步的一個好工具,使用過後我覺得它有以下幾個優點:
1. 簡單且實用
2. 跨平台(Windows/Mac/Linux/Mobile)
3. 2GB免費空間

如何於OpenSUSE 11.3上安裝:
1. zypper in docutils
2. tar jxvf nautilus-dropbox-0.6.3.tar.bz2 -C /usr/local/src/
3. cd /usr/local/src/nau*
4. ./configure && make && make install

安裝完畢後,就可以在最新安裝的應用程式裡找到它,當執行時會有wizard一步一步告訴你怎麼設定。我測試時是先把檔案透過Windows把檔案上傳到DropBox,然後切換到OpenSUSE看看,結果的確有檔案存在,不知道是不是使用的人還不多?上下傳檔案時還挺快的!

Sunday, September 12, 2010

Remove useless repositories by awk in OpenSUSE

帽客的桌機一路從OpenSUSE 11.1升級到OpenSUSE 11.3後,repositories都沒去清掉,導致一堆沒有在用的repos殘留在那邊,練習一下用awk把沒用的repos一次清光:
linux-8zbb:~ # zypper rr `zypper lr | awk '/No/{ print $3 }'`
Repository 'openSUSE' not found by alias, number or URI.
Removing repository 'Packman repository (openSUSE_11.1)' [done]
Repository 'Packman repository (openSUSE_11.1)' has been removed.
Removing repository 'openSUSE 11.2-0' [done]
Repository 'openSUSE 11.2-0' has been removed.
Removing repository 'opensuse11.2_oss' [done]
Repository 'opensuse11.2_oss' has been removed.
Removing repository 'opensuse11.2_update' [done]
Repository 'opensuse11.2_update' has been removed.
Removing repository 'opensuse_11.2_non-oss' [done]
Repository 'opensuse_11.2_non-oss' has been removed.
Removing repository 'opensuse 11.3 iso' [done]
Repository 'opensuse 11.3 iso' has been removed.
Removing repository 'packman' [done]
Repository 'packman' has been removed.
Removing repository 'openSUSE-11.1-Debug' [done]
Repository 'openSUSE-11.1-Debug' has been removed.
Removing repository 'openSUSE-11.1-Non-Oss' [done]
Repository 'openSUSE-11.1-Non-Oss' has been removed.
Removing repository 'openSUSE-11.1-Oss' [done]
Repository 'openSUSE-11.1-Oss' has been removed.
Removing repository 'openSUSE-11.1-Source' [done]
Repository 'openSUSE-11.1-Source' has been removed.
Removing repository 'openSUSE-11.1-Update' [done]
Repository 'openSUSE-11.1-Update' has been removed.
只能說awk好用又有效率~

Thursday, September 02, 2010

Configure ATI driver on OpenSUSE 11.3

SL410升級到OpenSUSE 11.3後竟然無法順利啟動X Server,做了一些事情後,讓X Server起來了可是得到的結果是....
1. 解析度只有1024*768
2. 沒有3D特效
3. 有開啟3D特效的user account,登入GNOME後,畫面一片空白

好吧,想說新增ATI driver for OpenSUSE 11.3的repository,沒想到更新後更慘,X Server又起不來了?只好先把它移除,然後上google找看看有沒有解法,果然有人提出了完美的更新方法,請注意作者有先說明:
ATI doesn’t provide anymore repository for their binary drivers, so we have to build them on each needed system. When the 11.3 hits the street, the procedure was complex and not so easy, now with their 10.7 ( 8.753 ) version, it’s doable.

照著這位前輩的作法,果然是重新搞定了我的桌面環境,實在是非常地感謝他呀,說起來ATI真是.......

Wednesday, September 01, 2010

Terminator

做帽客這一行的,常常要一次控制或是監控好幾台機器或是待測物,所以我的GNOME terminal就常開了一堆分頁,不過有時要同時"看"好幾台機器的狀況時,就只能忙碌的在好幾個分頁中切換,不然就是只能將它們個個獨立起來分開來看,然而這樣做實在不是很smart,所幸我今天發現了Terminator這樣的一個好工具,它主要的功能如下:

Terminator, multiple terminals in one window. The goal of this project is to produce a useful tool for arranging terminals. It is inspired by programs such as gnome-multi-term, quadkonsole, etc. in that the main focus is arranging terminals in grids (tabs is the most common default method, which Terminator also supports).


看起來很棒吧!實際上用起來的確也是非常nice!以下是它的官方網站:
順便整理一下目前得知的快捷鍵:
Ctrl-Shift-E: 新增terminal並垂直切割
Ctrl-Shift-O: 新增terminal並水平切割
Ctrl-Shift-P: 回到上一個terminal
Ctrl-Shift-N: 至下一個terminal
Ctrl-Shift-W: 關閉目前的terminal
Ctrl-Shift-Q: 結束terminator
F11: 全螢幕顯示

Example: 同時檢視IO, Memory還有CPU information:

Sunday, August 22, 2010

Saturday, August 21, 2010

How to enable bcm4312 wireless NIC

S10e升級到OpenSUSE 11.3後wireless起不來了,kernel需要重新安裝網卡的模組,透過以下的指令可以很方便的安裝起來:
/usr/sbin/install_bcm43xx_firmware

不過很奇怪,在公司使用時一直連不上AP,在家裡卻可以,不知道是不是公司的air太髒了 Orz....,anyway我覺得現在Linux desktop真是比以前方便了許多,不論是安裝套件或是硬體驅動,都比以前來的簡單多了,在此鼓勵大家多多使用opensource!

另外我目前於S10e上改用了Wicd取代了NetworkManager,原因是感覺好像在開自排車,只要設定好腳本,它就會偵測網路目前的狀況,若是以wire連接就優先使用wire,然而當wire出現若干問題時,就會去尋找wireless的連線,好處是當我帶著我的s10e於書房跟寢室時,它就會幫我設定好網路了,至於我呢嘿嘿~則是甚麼都不用做,只要呆呆上網就好了。

/etc/init.d/network restart? ifocnfig? iwconfig? iwlist? 點選NetworkManager選擇AP? 都不用了~

OpenSUSE 11.3 supports iPod/iPhone

OpenSUSE 11.3:
Access to iPhone and iPod touch files from nautilus.Rhythmbox can also play music from those devices.


OpenSUSE 11.3已經完全支援了iPod與iPhone,不過我沒買iPhone所以沒辦法實驗看看,其實我的要求也很簡單就是於Linux desktop中接上iPod然後播放音樂,是透過Linux desktop播放唷!實驗的結果真是出奇意外的好!
以下是簡單的步驟:

1. 安裝Rhythmbox:
# zypper in rhythmbox
2. 將音樂同步到iPod中:
我是透過ibook,這應該沒什麼好說的。 :p
3.開啟rhythmbox:
開啟rhythmbox後,馬上偵測到了我的iPod,並可以播放音樂了,中文顯示沒問題,也能把專輯封面顯示出來感覺就好像是用iTune播放,hey OpenSUSE11.3 is awesome!



Saturday, August 14, 2010

專訪Ruckus Wireless總裁CEO Selina Lo

所謂的「好」可分為兩種-優秀與傑出,專精在一件事情上,做到最好,就是優秀;若能跨出本身的領域,取經於其他專業,相互消化融合之後,才算是傑出。優秀的Wi-Fi無線橋接器很多,但堪稱真正傑出的產品,Ruckus Wireless必定是其中之一。

「Ruckus獨特的六角天線設計,其實來自於軍用雷達的天線設計。」Ruckus Wireless總裁暨執行長Selina Lo談到當初的創業之始:「共同創辦人暨無線架構長Victor Shtrom先前曾在IOSPAN Wireless公司便已經參加早期MIMO無線技術的研發,以及波音公司研究衛星電話系統等等,在無線技術上擁有許多專利。當時Victor Shtrom遇到另一個共同創辦人William Kish,專精於各種網路系統,尤其在路由系統方面甚有研究,因此雙方一拍即合,以網路技術加強無線電訊號配置,因此創辦了RuckusWireless。」

既然Ruckus Wireless的共同創辦人專精於各種無線技術,為何Ruckus Wireless的產品獨鍾Wi-Fi技術呢?Ruckus Wireless總裁暨執行長Selina Lo表示:「Wi-Fi技術可說是地球上最為普遍的無線傳輸方式之一,幾乎所有的手持裝置包括PDA、智慧型手機、筆記型電腦等,至少支援一種以上的Wi-Fi技術規格,而近年來,Wi-Fi也逐漸走出戶外,成為電信業者接取Last Mile的選項之一。」

Selina Lo認為,Wi – Fi的優點在於所使用的頻譜屬於免費空間,因此設備製造商與服務供應商不需要額外付出執照成本;但相對來看,W i – F i的缺點也是因為使用免費頻譜空間,所以干擾特別多,訊號並不穩定,「這也是Ruckus Wireless天線技術格外具備競爭力的地方,不但會隨時調整6組天線訊號幫助用戶端的連線穩定性,也能夠『拒絕』接收各種干擾源的訊號。其他品牌產品使用無指向性天線,只能被迫一併接受正常的傳輸訊號與干擾訊號,結果就是容易造成傳輸率下降或是連接不穩定。」

結合廣域無線技術

Ruckus Wireless由於長覆蓋距離、訊號穩定的特性,受到其他發展中國家的注意,將Wi-Fi技術納入「最後一哩」的選項中,甚至是關鍵角色。

印度在孟買、班加洛(Bangalore)等地,使用2.5萬臺Ruckus戶外Wi-Fi無線基地臺,為整座城市建立起Wi-Fi寬頻,而馬來西亞許多二級城市,也透過RuckusWireless的無線基地臺,讓Wi-Fi也能夠成為Back-haul骨幹網路之一,避免固網電纜常遭偷竊的困擾。

「目前我們也與其他WiMAX和LTE業者合作,以WiMAX/LTE作為骨幹網路無線傳輸標準,接地(landing)之後,透過Wi-Fi寬頻將訊號傳送至CPE端;如此一來,4G電信商便能夠快速佈署其服務,加快投資回收效率。」Selina Lo解釋道。

目前Ruckus Wireless產品可在1.5公里範圍內達到150Mbps的傳輸率,而在13公里範圍內還能維持60Mbps傳輸率,每基地臺同時可服務上千人,「所以Wi-Fi技術意外成為3G電信的好朋友,」Selina Lo表示:「自從iPhone全球大賣以來,3G服務訂閱人數便急遽上升,全球皆然。這對3G電信商來說應該是個好消息,但很快便發現使用3G的人愈多,整體利潤上升的速度便下降得愈快,主要原因在於3G基地臺的涵蓋範圍雖廣,但同時能夠服務的上線人數卻很有限,若要增加服務容量,就必須不斷佈署3G基地臺,這導致佈署成本節節上升。」

Selina Lo表示,香港PCCW很早便看到3G網路的困境,因此積極在全香港佈署Wi-Fi Hotzone,包括每個電話亭都放一個Wi-F i無線基地台,因此PCCW的手機客戶,只要在PCCW Wi-FiHotzone的覆蓋範圍內,便會轉接使用Wi-Fi無線網路上網,降低3G網路的數據傳輸負擔。

「這種方案我們稱之為3G Offload,能夠因應各種人群要求,例如球類比賽、演唱會等等,在特定區域快速佈署Wi-Fi Hotzone,紓解大量的行動上網需求,」Selina Lo談到Ruckus Wireless未來的主要方案:「根據PCCW的統計,在3G網路資料傳輸的尖峰時刻,3G Offload方案可以幫助PCCW有效減少20%以上的3G傳輸量,也幫PCCW降低不少成本壓力。」Selina Lo笑說。

臺灣市場前景佳

事實上,Ruckus Wireless與臺灣的關係相當密切,「創立之初,便在臺北成立研發中心,一方面是因為矽谷的Wireless人才不足,另一方面是因為臺灣是Wi-Fi製造大國,全球將近7成的Wi-Fi晶片或是卡片都是出自於臺灣設計,因此Ruckus Wireless設立臺北研發中心,的確幫助良多。」

在市場方面,Ruckus Wireless適合50人以上的中大型企業,如醫院、學校、製造業等等,「但RuckusWireless即將要在臺灣引進美國經驗,與IP-TV商合作,搭配類似MOD的方案以及Ruckus的Wi-Fi無線基地臺,使用者便可以在家中佈署HD-Video等級的無線網路,不需要牽線,便能夠讓家中所有如iPad、筆電等無線裝置觀看IP-TV節目。」根據Selina Lo提供的調查報告來看,在WWAN市場中,Ruckus Wireless在短短數年之間,便超越Cisco取得一半以上的市場佔有率。Selina Lo表示,相信以Ruckus Wireless獨特的產品競爭力,有機會能夠在家用市場再打下另一片戰場。

Tuesday, August 03, 2010

Install VirtualBox in OpenSUSE 11.3/64bit

其實以前在OpenSUSE 11.2 64bit的環境中安裝VirtualBox時,就會碰到無法順利啟動的問題,當時是以手動的方式解決rpm相依性的問題,但日子久了當升級到OpenSUSE 11.3時,我果然是忘記當初是怎麼解決的了 Orz,索性上google重新搜尋一番,沒想到找到了一個更棒的solution如下:

1. 新增VirtualBox的 software rep:
#zypper ar -f http://download.virtualbox.org/virtualbox/rpm/opensuse/11.3 vbox

2. 安裝VirtualBox:
# zypper in VirtualBox-3.2

3. 新增使用者至vboxusers group中:
比如我要account lawrence可以於X11中啟動VirtualBox時,必需將這個帳號新增到vboxusers group中。
# useradd(usermod) -G vboxusers lawrence


Monday, July 05, 2010

Speed up OpenOffice

找到了一篇說明如何加快執行OpenOffice的文章如下:

用OpenOffice 3.1.1搭配OpenSUSE 11.2,的確是感覺到啟動的速度加快了許多!Nice tip!

Saturday, May 01, 2010

[好文推薦] Collecting and analyzing Linux kernel crashes - crash

發現到一篇介紹如何分析Linux Kernel panic的好文章,先收藏起來有空再來研究下。

Sunday, April 25, 2010

OSX: ClickToFlash for Safari

在Linux下不論是使用Google Chrome或是Firefox,帽客都習慣安裝個外掛程式來把Flash block起來,原因是Flash實在是太吃CPU的resource了,尤其是在小筆電上開網頁跑Flash時是一件很痛苦的事情,今天花了一點時間找到了一個在OSX上for Safari的好工具來block Flash,使用過後整台Mac的效率提昇了不少,ClickToFlash實在是個好工具!老G4請繼續撐下去吧!

Saturday, April 24, 2010

RHEL6 Beta is available for public download!

RHEL6 Beta已經提供下載試用了!目前支援的平台有:
- i386
- AMD64/Intel64
- System z
- IBM Power 64

詳細的說明請到Redhat官網查看。

Install Skype on OpenSUSE 11.2 64bit

安裝Skype於OpenSUSE 11.2 64bit版本時發現到無法正常啟動,錯誤訊息如下:
./skype: error while loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory

解決的方法:
zypper install libQtGui.so.4z

FYI.

Wednesday, March 31, 2010

搞定802.11X

搞了一陣子,總算把802.11x的環境在家裡架了起來。
Test Environment:


- Windows XP SP3: 802.11x with PEAP and import CA that generated from FreeRADIU Server.
- OpenSUSE 11.2: 802.11x with PEAP and import CA that generated from FreeRADIUS Server.
- AP: Authentication via the Radius Server and configured data encrypt method as WPA2-AES.
- FreeRADIUS: Support PEAP as default.

總算是成功了:


Tuesday, March 30, 2010

To implement FreeRADIUS for LDAPs

架設流程:
Step1 ~ Step4 參考上次推薦的文章就可以架設起來,然而要實現FreeRADIUS for LDAPs只需要執行Step5就可以完成了,事實上也只是改變幾個參數。
1. To establish LDAP Server
2. To establish FreeRADIUS
3. To configure FreeRADIUS for LDAP
4. To establish LDAPs (TLS)
5. To establish FreeRADIUS for LDAPs:
修改step3中的radiusd.conf,讓FreeRADIUS知道要用LDAPs做認證。
# vi /etc/radiusd.conf
........................
ldap {
# set this to 'yes' to use TLS encrypted connections
# to the LDAP database by using the StartTLS extended
# operation.
# The StartTLS operation is supposed to be used with normal
# ldap connections instead of using ldaps (port 689) connections
start_tls = yes
tls_cacertfile = /etc/openldap/cacerts/client.pem
#tls_cacertdir = /usr/local/etc/openldap/ssl/
# tls_certfile = /path/to/radius.crt
# tls_keyfile = /path/to/radius.key
# tls_randfile = /path/to/rnd
tls_require_cert = "demand"

........................
}
測試:
於Server端執行radiusd -X,並於Client端透過radtest做驗證,以下是Server端的log:
rad_recv: Access-Request packet from host x.x.x.x:32896, id=190, length=60
219 User-Name = "ldapuser"
220 User-Password = "123456"
221 NAS-IP-Address = 255.255.255.255
222 NAS-Port = 0
223 Processing the authorize section of radiusd.conf
224 modcall: entering group authorize for request 0
225 modcall[authorize]: module "preprocess" returns ok for request 0
226 modcall[authorize]: module "chap" returns noop for request 0
227 modcall[authorize]: module "mschap" returns noop for request 0
228 rlm_realm: No '@' in User-Name = "ldapuser", looking up realm NULL
229 rlm_realm: No such realm "NULL"
230 modcall[authorize]: module "suffix" returns noop for request 0
231 rlm_eap: No EAP-Message, not doing EAP
232 modcall[authorize]: module "eap" returns noop for request 0
233 users: Matched entry DEFAULT at line 152
234 users: Matched entry DEFAULT at line 206
235 modcall[authorize]: module "files" returns ok for request 0
236 rlm_ldap: - authorize
237 rlm_ldap: performing user authorization for ldapuser
238 radius_xlat: '(uid=ldapuser)'
239 radius_xlat: 'dc=example,dc=com'
240 rlm_ldap: ldap_get_conn: Checking Id: 0
241 rlm_ldap: ldap_get_conn: Got Id: 0
242 rlm_ldap: attempting LDAP reconnection
243 rlm_ldap: (re)connect to x.x.x.x:389, authentication 0
244 rlm_ldap: setting TLS CACert File to /etc/openldap/cacerts/client.pem
245 rlm_ldap: setting TLS Require Cert to demand
246 rlm_ldap: could not set LDAP_OPT_X_TLS_REQUIRE_CERT option to demand
247 rlm_ldap: starting TLS
248 rlm_ldap: bind as / to x.x.x.x:389
249 rlm_ldap: waiting for bind result ...
250 rlm_ldap: Bind was successful
251 rlm_ldap: performing search in dc=example,dc=com, with filter (uid=ldapuser)
252 rlm_ldap: Added password {crypt}$1$/vvYrM2W$omOGg5A7NQVDxGcTb6afR1 in check items
253 rlm_ldap: looking for check items in directory...
254 rlm_ldap: looking for reply items in directory...
255 rlm_ldap: user ldapuser authorized to use remote access
256 rlm_ldap: ldap_release_conn: Release Id: 0
257 modcall[authorize]: module "ldap" returns ok for request 0
258 modcall: leaving group authorize (returns ok) for request 0
259 rad_check_password: Found Auth-Type LDAP
260 auth: type "LDAP"
261 Processing the authenticate section of radiusd.conf
262 modcall: entering group LDAP for request 0
263 rlm_ldap: - authenticate
264 rlm_ldap: login attempt by "ldapuser" with password "123456"
265 rlm_ldap: user DN: uid=ldapuser,ou=People,dc=example,dc=com
266 rlm_ldap: (re)connect to x.x.x.x:389, authentication 1
267 rlm_ldap: setting TLS CACert File to /etc/openldap/cacerts/client.pem
268 rlm_ldap: setting TLS Require Cert to demand
269 rlm_ldap: could not set LDAP_OPT_X_TLS_REQUIRE_CERT option to demand
270 rlm_ldap: starting TLS
271 rlm_ldap: bind as uid=ldapuser,ou=People,dc=example,dc=com/123456 to x.x.x.x:389
272 rlm_ldap: waiting for bind result ...
273 rlm_ldap: Bind was successful
274 rlm_ldap: user ldapuser authenticated succesfully
275 modcall[authenticate]: module "ldap" returns ok for request 0
276 modcall: leaving group LDAP (returns ok) for request 0
277 Sending Access-Accept of id 190 to x.x.x.x port 32896
Note: x.x.x.x 代表LDAP Server的FQDN或IP address。

Monday, March 29, 2010

介紹LDAP與FreeRADIUS的好文章

找到一篇介紹透過LDAP與FreeRADIUS做Linux系統帳號集中管理的方法,寫得挺不錯的,收藏起來。

Centralized Logins Using LDAP and RADIUS

Monday, March 22, 2010

Autoexpect Scenario

Autoexpect固然方便,但是很多時候還是必須手動改正Autoexpect所錄製過的script才能順利運行,以下將透過SSH登入本機後執行vmstat的指令來說明:

1. 執行Autoexpect:
# autoexpect
此時系統會產生一個autoexpect的shell環境,並將使用者的動作紀錄起來,離開時請輸入exit指令,之後系統會產生個script.exp的紀錄檔(By default)。

2. 執行script.exp:
lawrence@X60:~/Desktop> ./script.exp
spawn /bin/bash
lawrence@X60:~/Desktop> ssh root@127.0.0.1
Password:
此時會發覺停留在輸入Password:而不再有進一步的動作,這是為何呢?

3. 查看並修正script.exp:
原始script.exp(僅截取錄製的部份):
set timeout -1
spawn $env(SHELL)
match_max 100000
expect -exact "]2;lawrence@X60:~/Desktop]1;X60lawrence@X60:~/Desktop> "
send -- "ssh root@10"
expect -exact [K"
send -- ""
expect -exact [K"
send -- "127.0.0.1\r"
expect -exact "127.0.0.1\r
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.\r
RSA key fingerprint is fa:19:31:7a:ac:04:41:af:4c:38:b7:58:16:a3:14:f8.\r
Are you sure you want to continue connecting (yes/no)? "
send -- "yes\r"
expect -exact "yes\r
Warning: Permanently added '127.0.0.1' (RSA) to the list of known hosts.\r\r
Password: "
send -- "1234\r"
expect -exact "\r
Last login: Fri Mar 12 17:06:12 2010\r\r
Have a lot of fun...\r
[1m[31mX60:~ # [m"
send -- "vmstat -n 1 5\r"
expect -exact "vmstat -n 1 5\r
procs -----------memory---------- ---swap-- -----io---- -system-- -----cpu------\r
r b swpd free buff cache si so bi bo in cs us sy id wa st\r
14 0 25644 20660 26124 464024 0 1 17 23 881 255 7 3 89 1 0\r
0 0 25644 20148 26124 464536 0 0 0 0 1725 2206 6 2 93 0 0\r
0 0 25644 20404 26124 464264 0 0 0 0 1877 2234 3 3 95 0 0\r
0 0 25644 20404 26124 464224 0 0 0 0 1736 2186 4 1 95 0 0\r
0 0 25644 20404 26124 464224 0 0 0 0 1628 2168 3 2 95 0 0\r
[1m[31mX60:~ # [m"
send -- "ex"
expect -exact [K"
send -- ""
expect -exact [K"
send -- "logout\r"
expect -exact "logout\r
Connection to 127.0.0.1 closed.\r\r
]2;lawrence@X60:~/Desktop]1;X60lawrence@X60:~/Desktop> "
send -- "exit\r"
expect eof


問題1:
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.\r
RSA key fingerprint is fa:19:31:7a:ac:04:41:af:4c:38:b7:58:16:a3:14:f8.\r
Are you sure you want to continue connecting (yes/no)? "
預設SSH Server/Client連接時,會去紀錄對方的金鑰,也就是因為這個原因,讓expect沒有得到預期的輸出,因為SSH第n次連線後就不需要紀錄彼此的金鑰了。

問題2:
Last login: Fri Mar 12 17:06:12 2010\r\r
Have a lot of fun...\r
^[\[1m^[\[31mX60:~ # ^[(B^[\[m"
每次登入系統的時間一定會是不一樣的,所以把它也註解掉。

問題3:
procs -----------memory---------- ---swap-- -----io---- -system-- -----cpu------\r
r b swpd free buff cache si so bi bo in cs us sy id wa st\r
14 0 25644 20660 26124 464024 0 1 17 23 881 255 7 3 89 1 0\r
0 0 25644 20148 26124 464536 0 0 0 0 1725 2206 6 2 93 0 0\r
0 0 25644 20404 26124 464264 0 0 0 0 1877 2234 3 3 95 0 0\r
0 0 25644 20404 26124 464224 0 0 0 0 1736 2186 4 1 95 0 0\r
0 0 25644 20404 26124 464224 0 0 0 0 1628 2168 3 2 95 0 0\r
^[\[1m^[\[31mX60:~ # ^[(B^[\[m"
當然不需要上一次vmstat的輸出結果,所以也需要註解掉。

修改過後:
set timeout -1
spawn $env(SHELL)
match_max 100000
expect -exact "]2;lawrence@X60:~/Desktop]1;X60lawrence@X60:~/Desktop> "
send -- "ssh root@10"
expect -exact [K"
send -- ""
expect -exact [K"
send -- "127.0.0.1\r"
expect -exact "Password: "
send -- "1234\r"
expect -exact "#"
send -- "vmstat -n 1 5\r"
expect -exact "#"
send -- "ex"
expect -exact [K"
send -- ""
expect -exact [K"
send -- "logout\r"
expect -exact "logout\r
Connection to 127.0.0.1 closed.\r\r
]2;lawrence@X60:~/Desktop]1;X60lawrence@X60:~/Desktop> "
send -- "exit\r"
expect eof

4. 執行:
lawrence@X60:~/Desktop> ./script2.exp
spawn /bin/bash
lawrence@X60:~/Desktop> ssh root@127.0.0.1
Password:
Last login: Mon Mar 22 16:11:29 2010 from localhost
Have a lot of fun...
X60:~ # vmstat -n 1 5
procs -----------memory---------- ---swap-- -----io---- -system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 31016 27124 23500 454188 0 1 16 23 880 303 7 3 89 1 0
0 0 31016 29204 23500 451648 0 0 0 20 1815 1834 2 3 95 0 0
0 0 31016 29204 23500 451676 0 0 0 0 1821 1878 2 2 96 0 0
0 0 31016 29700 23500 451232 0 0 0 0 1763 2029 3 2 95 0 0
0 0 31016 29700 23500 451184 0 0 0 0 1807 2241 2 2 95 0 0
X60:~ # logout
Connection to 127.0.0.1 closed.
lawrence@X60:~/Desktop> exit
exit
lawrence@X60:~/Desktop>
Autoexpect雖然有以上的小缺點,但還是能加快script開發的速度。