- 論壇徽章:
- 1
|
MSN 通常是用來交談的, Liunx 下最有名的 MSN Client 當(dāng)屬 gaim,
不過因為它是 GUI 的環(huán)境,要以 shell 來應(yīng)用實在不容易
(如果你能用 shell 控制 mouse 點在那裏就可以做到,但你能嗎 ? ()
1. 安裝 tmsnc (http://tmsnc.sourceforge.net/download.html)
我的例子是用 0.1.1 版本,你可以找別的版本自己開發(fā),或參考我的例子也可以
- $>wget http://unc.dl.sourceforge.net/sourceforge/tmsnc/tmsnc-0.1.1.tar.gz
- $>tar -zxvf tmsnc-0.1.1.tar.gz
- $>cd tmsnc-0.1.1
- # 看一下 Makefile , 裏面的 openssl 路徑是否符合你的環(huán)境
- $>make
- $>make install
- $>tmsnc (啟動的樣子)
- .........
- .'------.' |
- | .-----. | |
- | |TMSNC| | |;.
- |*`-----'.|.' `;
- `---------' .;'
- .''''////////;'
- / ######### /;/ The
- / ######### // textbased
- `-----------' alternative!
- Login: abel@twnic.net.tw
- Your login-address is abel@twnic.net.tw
- Enter password:
復(fù)制代碼
2.TMSNC 的指令說明
- # tmsnc 的 command 說明 (Readme),如果你要完善你的功能,就要詳讀任何的說明
- Availible commands in TMSNC are:
- * help show a list of availible commands
- * clear clear the screen
- * nick <name> set your nickname to <name>
- * status <string> where <string> is online, busy, brb,
- * away, phone, lunch or hidden
- * quit logout from server and quit TMSNC
- * add <address> add <address> to the contact-list
- * block <address> prevent <address> from obtaining your status
- * unblock <address> reverse the block
- * remove <address> remove <address> from contact-list
- * window <n> or TAB change current window to <n>
- * window close or F7 close current window and conversation
- * chat <address> or Enter start a new conversation with <address>
復(fù)制代碼
由以上我們可以知道, tmsnc 我們巳經(jīng)裝好了,所以就可以來做 shell 發(fā)送 msn 的工作了!
用 shell 來發(fā),最好的工具是 expect , 這個工具的說明,你可以在 man page 中找到詳細(xì)
解說
3.
3.1
範(fàn)例一(簡單版):
- #!/usr/bin/expect
- # filename=send.exp
- log_file ./exp.log
- spawn tmsnc -l 你申請的MSN帳號
- expect "Enter password:"
- send "你的密碼\r"
- expect -re ".* can't control me*"
- sleep 5
- send "/chat [lindex $argv 0]\n"
- expect -re ".*!.*"
- sleep 1
- send "Now: [exec date]\n"
- sleep 1
- send "[lindex $argv 1]\n"
- sleep 3
- send "/window close\r"
- send "/quit\r"
復(fù)制代碼
用法:
- #請注意, MSN訊息需為 UTF-8 encoding
- $>./send.exp MSN連絡(luò)人 MSN訊息
復(fù)制代碼
3.1
範(fàn)例二(稍複雜版):
[code]
#!/usr/bin/expect
# log file , for debug
log_file ./exp.log
#設(shè)定訊息路經(jīng)
set workdir "/www/htdocs/html/msn/msg"
# -l 指定 MSN contact, 你可以 tmsnc -h 來了解參數(shù)
spawn tmsnc -l 你申請的MSN帳號
sleep 1
# 出現(xiàn) password 時,送出密碼
expect "Enter password:"
send "你的密碼\r"
sleep 1
# 出現(xiàn) control me 時,表示 tmsnc 載入完成
expect -re ".* can't control me*"
sleep 3
# 無限迴圈,讀取訊息檔
while {1} {
sleep 1
#取得 訊息檔中第一行,我個人的定義是 MSN addr
set msn_addr [ exec cat $workdir/msg.utf8 | head -1 ]
#如果 |
-
cu-reply.gif
(17.89 KB, 下載次數(shù): 78)
下載附件
2005-07-11 14:01 上傳
mysql_alert.sh 發(fā)送的例子
|