In bash:
#!/bin/bash
expect -c "
spawn ssh root@1.1.1.1
expect password:
send \"1234\r\"
expect ]#
send \"ls -l\r\"
expect ]#
send \"uname -r\r\"
expect -timeout 1
"
Not in bash:
#!/usr/bin/expect
spawn ssh root@1.1.1.1
expect "password: "
send "1234\r"
expect "]# "
send "uname -r\r"
expect -timeout 1
Monday, November 17, 2008
Friday, October 31, 2008
dmidecode
Windows下相信大家常用cpuz去查看主機板的詳細資訊,而Linux下則可用dmidecode這個工具來查看,這邊是dmidecode官網的example: dmidecode example。
安裝的方法非常簡單,將tarball檔抓下來後,進入到解開的目錄中執行:make;make install即可安裝成功,而執行時直接打dmidecode就可以了,配合重新輸出導向,就可將此info記錄到某一檔案中。
Wednesday, October 22, 2008
Check USB status in Linux
簡單介紹一下如何在Linux OS下查看USB的控制器與其它資訊,一個非常簡單的方法是透過lspci,如下所示:
[root@s1 ~]# lspci | grep -i usb
00:07.2 USB Controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller (rev 16)
00:07.3 USB Controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller (rev 16)
可以看出這台老PC只支援USB 1.x
PS. USB 控制器:
-UHCI: USB 1.x Inetl/VIA mb
-OHCI: USB 1.x 非Intel/VIA mb
-EHCI: USB 2.0
另外一個包含非常多USB資訊的檔案:
[root@s1 ~]# cat /proc/bus/usb/devices
T: Bus=02 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2
B: Alloc= 0/900 us ( 0%), #Int= 0, #Iso= 0
D: Ver= 1.10 Cls=09(hub ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=0000 ProdID=0000 Rev= 2.06
S: Manufacturer=Linux 2.6.18-53.el5 uhci_hcd
S: Product=UHCI Host Controller
S: SerialNumber=0000:00:07.3
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr= 0mA
I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
E: Ad=81(I) Atr=03(Int.) MxPS= 2 Ivl=255ms
T: Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2
B: Alloc= 0/900 us ( 0%), #Int= 0, #Iso= 0
D: Ver= 1.10 Cls=09(hub ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=0000 ProdID=0000 Rev= 2.06
S: Manufacturer=Linux 2.6.18-53.el5 uhci_hcd
S: Product=UHCI Host Controller
S: SerialNumber=0000:00:07.2
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr= 0mA
I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
E: Ad=81(I) Atr=03(Int.) MxPS= 2 Ivl=255ms
Wednesday, October 15, 2008
利用PAM限制SSH login的user account
實作起來非常簡單,兩個設定即可,請參考如下:
需求:只允許root與u1可以ssh login至本機
1. 建立user list:
# vi /etc/ssh/ssh_users
root
u1
2. 修改/etc/pam.d/sshd:
#%PAM-1.0
#auth include system-auth
auth required pam_listfile.so item=user sense=allow file=/etc/ssh/ssh_users onerr=fail
account required pam_nologin.so
account include system-auth
password include system-auth
session optional pam_keyinit.so force revoke
session include system-auth
session required pam_loginuid.so
立即生效~
* sense=allow 代表名列於/etc/ssh/ssh_users的user才可ssh login, 反過來說當sense=deny時代表ssh_users中的account不可ssh login。
*onerr=fail 代表當/etc/ssh/ssh_users無法開啟或是檔案不存在時,當作失敗,反之onerr=succeed代表不管能不能讀取到檔案都成功。
Monday, September 22, 2008
翻得真好~
最近常看三國演義, 並看到這句話: A good bird chooses (for himself) the tree upon which to perch, the talented subject chooses (for himself) the lord that he shall.
有人知道怎麼將它翻回原文嗎? 先賣個關子
有人知道怎麼將它翻回原文嗎? 先賣個關子
Friday, September 19, 2008
讓Windows XP也有Mac or Linux-like multiple desktop
帽客的小萬螢幕不夠大, 往往開了一堆App後Windows的工具列就雜亂很難看, 然而這個情況改變了, 今天碰巧的發現到原來老M也出了類似Mac與Linux的多工桌面環境, 你可以至以下的MS官方網址抓取使用:
http://technet.microsoft.com/en-us/sysinternals/cc817881.aspx

謎之音: 小萬:[快把我改裝成Linux啦~~~~]
我: [先用Virtualbox撐一下吧~]
http://technet.microsoft.com/en-us/sysinternals/cc817881.aspx
謎之音: 小萬:[快把我改裝成Linux啦~~~~]
我: [先用Virtualbox撐一下吧~]
Thursday, September 18, 2008
Acer ASPIRE one BIOS update
New BIOS of Acer ASPIRE one (AOA110/AOA150) is available to download:
http://www.acer.com.tw/driver.asp
V.3304
http://www.acer.com.tw/driver.asp
V.3304
Thursday, September 11, 2008
LDIF generate tools: OpenDS內附的"makeldif"
提供一個大量產生LDIF user entries的產生器:
https://www.opends.org/wiki/page/MakeLdif
Download site
執行makeldif前,系統必須安裝JRE的環境,所以請到Sun官網抓吧:
Sun JRE
安裝好JRE後, 就可以順利透過makeldif產生大量的資料了,預設是10K.
最後提供一套在Windows下查詢LDAP Server user entries的好工具, 一樣Windows也必須有JRE:
LDAP Browser/Editor
Note:
Tested on CentOS5.2
https://www.opends.org/wiki/page/MakeLdif
Download site
執行makeldif前,系統必須安裝JRE的環境,所以請到Sun官網抓吧:
Sun JRE
安裝好JRE後, 就可以順利透過makeldif產生大量的資料了,預設是10K.
最後提供一套在Windows下查詢LDAP Server user entries的好工具, 一樣Windows也必須有JRE:
LDAP Browser/Editor
Note:
Tested on CentOS5.2
Friday, September 05, 2008
更新Acer Aspire one BIOS
上星期帽客到黃色小屋敗了一台小筆電 Acer Aspire one XP120G(金色的那款), 目前使用上沒有遇到太大的問題, 唯一的就是當LCD亮度調到比較暗時, LCD會閃爍不停 :(
這個問題還挺多人遇到的, 不過Acer已經有釋放出BIOS來解決這個問題了, 新BIOS的版本為3301, 但是此時我需要USB開機碟, 上google爬了爬文, 發現到BootFlashDOS這個製作USB開機碟的好東東, 簡單又快速 XD
製作好USB開機碟後於XP中重新開機Acer Aspire one, 並按下F12選擇用USB開機, 開完後執行3301.bat, 待重開機後, BIOS更新成功, LCD閃爍的問題似乎也得到了改善, 且讓我再觀察一陣子看看.
另外還有人抱怨Aspire one 無線訊號不良與底座不平這兩個主要問題, 我使用上的感覺是:
-無線訊號不良: 還ok 連公司的AP都算順暢, 不過只有用MAC filter,如果有跑加密呢? 呵~應該跟我的3com AP來連看看, anyway我很少用wireless所以這點對我問題不大
-底座不平: 這點到還好, 如果拔掉電池, 一點也沒有不平的感覺, 裝上電池呢? 這點容我再留意一下
這個問題還挺多人遇到的, 不過Acer已經有釋放出BIOS來解決這個問題了, 新BIOS的版本為3301, 但是此時我需要USB開機碟, 上google爬了爬文, 發現到BootFlashDOS這個製作USB開機碟的好東東, 簡單又快速 XD
製作好USB開機碟後於XP中重新開機Acer Aspire one, 並按下F12選擇用USB開機, 開完後執行3301.bat, 待重開機後, BIOS更新成功, LCD閃爍的問題似乎也得到了改善, 且讓我再觀察一陣子看看.
另外還有人抱怨Aspire one 無線訊號不良與底座不平這兩個主要問題, 我使用上的感覺是:
-無線訊號不良: 還ok 連公司的AP都算順暢, 不過只有用MAC filter,如果有跑加密呢? 呵~應該跟我的3com AP來連看看, anyway我很少用wireless所以這點對我問題不大
-底座不平: 這點到還好, 如果拔掉電池, 一點也沒有不平的感覺, 裝上電池呢? 這點容我再留意一下
Tuesday, September 02, 2008
永久掛載smbfs/cifs filesystem時 於/etc/fstab不顯示user info
以前帽客在/etc/fstab mount smb/cifs的遠端FileServer時, 總是壞習慣的把username與password寫在/etc/fstab中, 不太好也不建議, 所以目前改用以下的方法將username與password存入到別的檔案, 而在/etc/fstab中則指定去讀這個檔案以取得user的相關info, 整個fstab的格式改變如下:
-before:
//172.17.1.254/homes /mnt/smb cifs defaults,username=lawrence%redhat
-after:
//172.17.1.254/homes /mnt/smb cifs defaults,credentials=/root/creds
/root/creds 內容:
username=lawrence
password=redhat
* /root/creds 權限建議設定為400
-before:
//172.17.1.254/homes /mnt/smb cifs defaults,username=lawrence%redhat
-after:
//172.17.1.254/homes /mnt/smb cifs defaults,credentials=/root/creds
/root/creds 內容:
username=lawrence
password=redhat
* /root/creds 權限建議設定為400
Friday, August 29, 2008
queryperf: 測試DNS Server的效能/壓力工具
今天找到了一個對於DNS Server做stress test的好工具: queryperf,這個工具事實上內建於bind套件中,不過我的Centos5.2與OpenSUSE10是透過rpm安裝bind的,利用rpm -ql | grep -i queryperf卻找不到相關的檔案?於是乎我去抓了bind tarball檔,將queryperf compile起來,產生queryperf binary file就可以使用了。
使用的語法也不難主要如下:
./queryperf -d -s
-d 是讀取測試RR文檔的意思
-s 是指定所要測試的DNS Server
RR_document的格式也是很簡單的,請參考以下範例:
server1.example.com A -> query server1.example.com A Record
example.com MX -> query example.com domain mx Record
mail.example.com CNAME -> query mail.example.com CNAME
server1.example.com TXT -> query server1.example.com TXT Record
example.com TXT -> query example.com domain TXT Record
example.com NS -> query example.com domain NS Record
100.10.10.10.in-addr.arpa PTR -> query 10.10.10.100 PTR Record
101.10.10.10.in-addr.arpa PTR -> query 10.10.10.101 PTR Record
Note: ->是說明,不需要加入到RR_document
執行結果:
Statistics:
Parse input file: once
Ended due to: reaching end of file
Queries sent: 8 queries
Queries completed: 8 queries
Queries lost: 0 queries
Queries delayed(?): 0 queries
RTT max: 0.033874 sec
RTT min: 0.013128 sec
RTT average: 0.023992 sec
RTT std deviation: 0.007508 sec
RTT out of range: 0 queries
Percentage completed: 100.00%
Percentage lost: 0.00%
Started at: Mon Aug 25 03:33:47 2008
Finished at: Mon Aug 25 03:33:47 2008
Ran for: 0.034861 seconds
Queries per second: 229.482803 qps
緊接著來寫個簡單的script讓他不斷的執行queryperf吧!
#!/bin/bash
while true
do
./queryperf -d dnstest -s $1 -v
done
把DNS所有的RR都寫入RR_document,這麼一來,就可以來試看看你的DNS Server耐不耐操了 XD!
使用的語法也不難主要如下:
./queryperf -d
-d 是讀取測試RR文檔的意思
-s 是指定所要測試的DNS Server
RR_document的格式也是很簡單的,請參考以下範例:
server1.example.com A -> query server1.example.com A Record
example.com MX -> query example.com domain mx Record
mail.example.com CNAME -> query mail.example.com CNAME
server1.example.com TXT -> query server1.example.com TXT Record
example.com TXT -> query example.com domain TXT Record
example.com NS -> query example.com domain NS Record
100.10.10.10.in-addr.arpa PTR -> query 10.10.10.100 PTR Record
101.10.10.10.in-addr.arpa PTR -> query 10.10.10.101 PTR Record
Note: ->是說明,不需要加入到RR_document
執行結果:
Statistics:
Parse input file: once
Ended due to: reaching end of file
Queries sent: 8 queries
Queries completed: 8 queries
Queries lost: 0 queries
Queries delayed(?): 0 queries
RTT max: 0.033874 sec
RTT min: 0.013128 sec
RTT average: 0.023992 sec
RTT std deviation: 0.007508 sec
RTT out of range: 0 queries
Percentage completed: 100.00%
Percentage lost: 0.00%
Started at: Mon Aug 25 03:33:47 2008
Finished at: Mon Aug 25 03:33:47 2008
Ran for: 0.034861 seconds
Queries per second: 229.482803 qps
緊接著來寫個簡單的script讓他不斷的執行queryperf吧!
#!/bin/bash
while true
do
./queryperf -d dnstest -s $1 -v
done
把DNS所有的RR都寫入RR_document,這麼一來,就可以來試看看你的DNS Server耐不耐操了 XD!
Friday, August 22, 2008
控管非Linux風格的file system的權限
現今Linux已經可以支援許多非Linux的檔案系統了,比如vfat,ntfs,hpfs,hfs等等,而預設上只有root可以對這些非Linux風格的檔案系統做新增與刪除的動作,其他一般user是不被允許的,或許有人覺得,還好吧!那我用chown硬上看看,但得到的結果會是.... Operation not permitted,非常遺憾呢~ 然而小弟不才今天發現到了可行的方案,在此提供給各位參考:
解決的方法非常簡單,用mount參數就可以解決了!
uid=lawrence ->代表此檔案系統中所有的檔案的使用者都是lawrence
gid=qa -> 代表此檔案系統中所有的檔案的群組都是qa
umask=027 -> 類似原本umask的功能,只不過不分檔案與目錄所有預設的權限都是777 (Linux filesystem 新增檔案時權限為666,目錄為777),所以此檔案系統的權限為750
整個mount指令下達: mount -t vfat -o uid=lawrence,gid=qa,umask=027 /dev/hdaX /mnt/msdos
(-t vfat可不輸入)
解決的方法非常簡單,用mount參數就可以解決了!
uid=lawrence ->代表此檔案系統中所有的檔案的使用者都是lawrence
gid=qa -> 代表此檔案系統中所有的檔案的群組都是qa
umask=027 -> 類似原本umask的功能,只不過不分檔案與目錄所有預設的權限都是777 (Linux filesystem 新增檔案時權限為666,目錄為777),所以此檔案系統的權限為750
整個mount指令下達: mount -t vfat -o uid=lawrence,gid=qa,umask=027 /dev/hdaX /mnt/msdos
(-t vfat可不輸入)
Thursday, August 21, 2008
Colasoft Packet Builder
帽客很少介紹在Windows上的軟體,不過我覺得從事網通業的各位朋友們如果使用了這套軟體,對於網路行為的除錯應該是有些幫助,Colasoft Packet Builder是一套在Windows作業系統上的免費軟體,透過它我們可以製造出想要的TCP, UDP, IP, ARP的封包,好用的是我發現到它還load一些capture packets的紀錄檔(sniffer/wireshark),修改過後再產生packets,感謝D-Link大大Dennis的介紹~
Colasoft Packet Builder
Colasoft Packet Builder
Friday, August 15, 2008
忽視fsck 當mount filesystem達到指定的數量
有使用Ubuntu的朋友們應該有發現到,有時開機時會顯示正在fsck filesystem,這時只能去泡杯茶等它檢查完畢了,當然這樣對於filesystem的完整性並避免磁碟的錯誤是有幫助的,但是有時帽客實在是不太想等Ubuntu的這個好意,所以我用以下的方法將它取消:
1.先使用dumpe2fs得到mount幾次後就會fsck filesystem:
lawrence@lawrence-x24:~$ sudo dumpe2fs /dev/sda3 | grep -i mount
dumpe2fs 1.40.8 (13-Mar-2008)
Last mounted on:
Default mount options: (none)
Last mount time: Fri Aug 15 09:03:55 2008
Mount count: 27
Maximum mount count: 35
得到目前mount 27次,並於第35次時會fsck filesystem。
2.使用tune2fs修改Maximum mount count為-1(永不fck):
lawrence@lawrence-x24:~$ sudo tune2fs -c -1 /dev/sda3
tune2fs 1.40.8 (13-Mar-2008)
Setting maximal mount count to -1
lawrence@lawrence-x24:~$ sudo dumpe2fs /dev/sda3 | grep -i mount
dumpe2fs 1.40.8 (13-Mar-2008)
Last mounted on:
Default mount options: (none)
Last mount time: Fri Aug 15 09:03:55 2008
Mount count: 27
Maximum mount count: -1
實際上還有個參數,當經過多久後,也會fsck filesystem:
lawrence@lawrence-x24:~$ sudo dumpe2fs /dev/sda3 | grep -i inter
dumpe2fs 1.40.8 (13-Mar-2008)
Check interval: 15552000 (6 months)
看來預設是6個月,恩這樣倒不錯。
1.先使用dumpe2fs得到mount幾次後就會fsck filesystem:
lawrence@lawrence-x24:~$ sudo dumpe2fs /dev/sda3 | grep -i mount
dumpe2fs 1.40.8 (13-Mar-2008)
Last mounted on:
Default mount options: (none)
Last mount time: Fri Aug 15 09:03:55 2008
Mount count: 27
Maximum mount count: 35
得到目前mount 27次,並於第35次時會fsck filesystem。
2.使用tune2fs修改Maximum mount count為-1(永不fck):
lawrence@lawrence-x24:~$ sudo tune2fs -c -1 /dev/sda3
tune2fs 1.40.8 (13-Mar-2008)
Setting maximal mount count to -1
lawrence@lawrence-x24:~$ sudo dumpe2fs /dev/sda3 | grep -i mount
dumpe2fs 1.40.8 (13-Mar-2008)
Last mounted on:
Default mount options: (none)
Last mount time: Fri Aug 15 09:03:55 2008
Mount count: 27
Maximum mount count: -1
實際上還有個參數,當經過多久後,也會fsck filesystem:
lawrence@lawrence-x24:~$ sudo dumpe2fs /dev/sda3 | grep -i inter
dumpe2fs 1.40.8 (13-Mar-2008)
Check interval: 15552000 (6 months)
看來預設是6個月,恩這樣倒不錯。
Thursday, August 14, 2008
Process執行中止時便停止追蹤(tail -f)
tail -f 可以持續顯示新增的檔案內容,對於協助追蹤某些檔案的內容變化非常有幫助,但事實上如果process已經沒有繼續執行的時候,那麼意義可能不大,所幸還是有解決的方法,利用--pid= 就可以做到,以下是實際演練:
1. ping hinet苦命的DNS 168.95.1.1,並將結果redirect到/tmp/test
# ping 168.95.1.1 > /tmp/test &
2.利用tail持續追蹤/tmp/test,並輸入ping process的pid
# tail -f --pid=xxxx /tmp/test
3. 中止ping
# killall ping
此時應該會看到類似這樣的行為:
[root@server2 tmp]# ping 168.95.1.1 > /tmp/test &
[1] 11024
[root@server2 tmp]# tail -f --pid=11024 /tmp/test
64 bytes from 168.95.1.1: icmp_seq=1 ttl=239 time=52.6 ms
64 bytes from 168.95.1.1: icmp_seq=2 ttl=246 time=21.4 ms
64 bytes from 168.95.1.1: icmp_seq=3 ttl=246 time=19.9 ms
64 bytes from 168.95.1.1: icmp_seq=4 ttl=246 time=19.6 ms
64 bytes from 168.95.1.1: icmp_seq=5 ttl=246 time=18.4 ms
64 bytes from 168.95.1.1: icmp_seq=6 ttl=239 time=50.9 ms
64 bytes from 168.95.1.1: icmp_seq=7 ttl=246 time=17.6 ms
64 bytes from 168.95.1.1: icmp_seq=8 ttl=246 time=19.1 ms
64 bytes from 168.95.1.1: icmp_seq=9 ttl=239 time=51.4 ms
64 bytes from 168.95.1.1: icmp_seq=10 ttl=246 time=18.1 ms
64 bytes from 168.95.1.1: icmp_seq=11 ttl=239 time=52.3 ms
64 bytes from 168.95.1.1: icmp_seq=12 ttl=246 time=20.6 ms
64 bytes from 168.95.1.1: icmp_seq=13 ttl=246 time=18.9 ms
64 bytes from 168.95.1.1: icmp_seq=14 ttl=239 time=53.4 ms
64 bytes from 168.95.1.1: icmp_seq=15 ttl=246 time=18.6 ms
64 bytes from 168.95.1.1: icmp_seq=16 ttl=246 time=18.5 ms
64 bytes from 168.95.1.1: icmp_seq=17 ttl=246 time=18.9 ms
[1]+ Terminated ping 168.95.1.1 >/tmp/test ping被kill了所以也就停止追蹤了。
1. ping hinet苦命的DNS 168.95.1.1,並將結果redirect到/tmp/test
# ping 168.95.1.1 > /tmp/test &
2.利用tail持續追蹤/tmp/test,並輸入ping process的pid
# tail -f --pid=xxxx /tmp/test
3. 中止ping
# killall ping
此時應該會看到類似這樣的行為:
[root@server2 tmp]# ping 168.95.1.1 > /tmp/test &
[1] 11024
[root@server2 tmp]# tail -f --pid=11024 /tmp/test
64 bytes from 168.95.1.1: icmp_seq=1 ttl=239 time=52.6 ms
64 bytes from 168.95.1.1: icmp_seq=2 ttl=246 time=21.4 ms
64 bytes from 168.95.1.1: icmp_seq=3 ttl=246 time=19.9 ms
64 bytes from 168.95.1.1: icmp_seq=4 ttl=246 time=19.6 ms
64 bytes from 168.95.1.1: icmp_seq=5 ttl=246 time=18.4 ms
64 bytes from 168.95.1.1: icmp_seq=6 ttl=239 time=50.9 ms
64 bytes from 168.95.1.1: icmp_seq=7 ttl=246 time=17.6 ms
64 bytes from 168.95.1.1: icmp_seq=8 ttl=246 time=19.1 ms
64 bytes from 168.95.1.1: icmp_seq=9 ttl=239 time=51.4 ms
64 bytes from 168.95.1.1: icmp_seq=10 ttl=246 time=18.1 ms
64 bytes from 168.95.1.1: icmp_seq=11 ttl=239 time=52.3 ms
64 bytes from 168.95.1.1: icmp_seq=12 ttl=246 time=20.6 ms
64 bytes from 168.95.1.1: icmp_seq=13 ttl=246 time=18.9 ms
64 bytes from 168.95.1.1: icmp_seq=14 ttl=239 time=53.4 ms
64 bytes from 168.95.1.1: icmp_seq=15 ttl=246 time=18.6 ms
64 bytes from 168.95.1.1: icmp_seq=16 ttl=246 time=18.5 ms
64 bytes from 168.95.1.1: icmp_seq=17 ttl=246 time=18.9 ms
[1]+ Terminated ping 168.95.1.1 >/tmp/test ping被kill了所以也就停止追蹤了。
Wednesday, August 13, 2008
刪除當前目錄備份檔(*~)的方法
我想到的方法分別有三種如下:
1. find ./ -iname "*~" -exec rm {} \;
2. find ./ -iname "*~" | xargs rm
3. rm `find ./ -iname "*~"`
如果您有更好的方法,煩請告知囉~
1. find ./ -iname "*~" -exec rm {} \;
2. find ./ -iname "*~" | xargs rm
3. rm `find ./ -iname "*~"`
如果您有更好的方法,煩請告知囉~
Thursday, August 07, 2008
Howto mount disk image
如果你今天面對的是disk image而不是一般的partition image,當使用mount -o loop時會無法mount成功。這很容易理解,因為你必須知道disk image中partition的位置後才能mount起來,怎麼做呢?以下將會說明:
需求: mount test.img 並更改第一個partition中的某個檔案
我們先看看如果直接用mount -o loop會如何:
lawrence@lawrence-x24:~/Desktop$ sudo mount -o loop test.img /mnt/test/
mount: you must specify the filesystem type
lawrence@lawrence-x24:~/Desktop$ sudo mount -o loop -t ext3 test.img /mnt/test/
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so
恩,看起來是不work......
所以我必須先知道test.img的磁軌與磁區大小才能算出第一個partition的位置:
lawrence@lawrence-x24:~/Desktop$ fdisk -l test.img
You must set cylinders.
You can do this from the extra functions menu.
Disk test.img: 0 MB, 0 bytes
16 heads, 63 sectors/track, 0 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Disk identifier: 0x00000000
所用裝置 Boot Start End Blocks Id System
test.img1 1 32 16096+ 83 Linux
得知每個 track 共 63 sectors, 每個 sector 是 512bytes,故得知第一個partition是在63*512=32256。
接下來利用losetup將第一個partition先掛到/dev/loop0,並驗證:
lawrence@lawrence-x24:~/Desktop$ sudo losetup --offset 32256 /dev/loop0 test.img
lawrence@lawrence-x24:~/Desktop$ sudo losetup /dev/loop0
/dev/loop0: [0803]:865823 (test.img), offset 32256
好了,將它mount起來吧!
lawrence@lawrence-x24:~/Desktop$ sudo mount /dev/loop0 /mnt/test/
lawrence@lawrence-x24:~/Desktop$ df -h | grep test
/dev/loop0 16M 7.9M 6.6M 55% /mnt/test
修改完畢後,一樣將他umount掉並detach /dev/loop0
lawrence@lawrence-x24:/mnt/test$ cd
lawrence@lawrence-x24:~$ sudo umount /mnt/test
lawrence@lawrence-x24:~$ df -h | grep test
lawrence@lawrence-x24:~$ sudo losetup -d /dev/loop0
lawrence@lawrence-x24:~$ sudo losetup /dev/loop0
loop: can't get info on device /dev/loop0: 沒有此一裝置或位址
以上希望對大家有幫助。
PS. Redhat中如果要位移,是下達losetup -o 32256而不是losetup --offset 32256
需求: mount test.img 並更改第一個partition中的某個檔案
我們先看看如果直接用mount -o loop會如何:
lawrence@lawrence-x24:~/Desktop$ sudo mount -o loop test.img /mnt/test/
mount: you must specify the filesystem type
lawrence@lawrence-x24:~/Desktop$ sudo mount -o loop -t ext3 test.img /mnt/test/
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so
恩,看起來是不work......
所以我必須先知道test.img的磁軌與磁區大小才能算出第一個partition的位置:
lawrence@lawrence-x24:~/Desktop$ fdisk -l test.img
You must set cylinders.
You can do this from the extra functions menu.
Disk test.img: 0 MB, 0 bytes
16 heads, 63 sectors/track, 0 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Disk identifier: 0x00000000
所用裝置 Boot Start End Blocks Id System
test.img1 1 32 16096+ 83 Linux
得知每個 track 共 63 sectors, 每個 sector 是 512bytes,故得知第一個partition是在63*512=32256。
接下來利用losetup將第一個partition先掛到/dev/loop0,並驗證:
lawrence@lawrence-x24:~/Desktop$ sudo losetup --offset 32256 /dev/loop0 test.img
lawrence@lawrence-x24:~/Desktop$ sudo losetup /dev/loop0
/dev/loop0: [0803]:865823 (test.img), offset 32256
好了,將它mount起來吧!
lawrence@lawrence-x24:~/Desktop$ sudo mount /dev/loop0 /mnt/test/
lawrence@lawrence-x24:~/Desktop$ df -h | grep test
/dev/loop0 16M 7.9M 6.6M 55% /mnt/test
修改完畢後,一樣將他umount掉並detach /dev/loop0
lawrence@lawrence-x24:/mnt/test$ cd
lawrence@lawrence-x24:~$ sudo umount /mnt/test
lawrence@lawrence-x24:~$ df -h | grep test
lawrence@lawrence-x24:~$ sudo losetup -d /dev/loop0
lawrence@lawrence-x24:~$ sudo losetup /dev/loop0
loop: can't get info on device /dev/loop0: 沒有此一裝置或位址
以上希望對大家有幫助。
PS. Redhat中如果要位移,是下達losetup -o 32256而不是losetup --offset 32256
Friday, August 01, 2008
線上學習Linux
發現到一個線上學習Linux的好地方,文章非常豐富,英文用詞也不會太難,且也提供html與PDF的下載,真是滿不錯的,非常感謝這些無私奉獻的人。
http://learnlinux.tsf.org.za/index.html
http://learnlinux.tsf.org.za/index.html
Thursday, July 24, 2008
讓FreeRadius Server整合Linux上的帳號做認證
很久以前有介紹透過FreeRadius Server裡的users來做使用者認證,在此update一下透過Linux本機帳號來做認證。
Step1. 將啟動radius server的使用者改為root
如果不這麼做的話,當啟動radius server時,由於radiusd user對於/etc/shadow沒有讀取的權限,故會發生permission denied。網路上有找到PAM Support for FreeRadius (http://www.sfr-fresh.com/unix/misc/freeradius-1.0.5.tar.gz:a/freeradius-1.0.5/doc/rlm_pam)的文章,可是照著做還是不能work,所以先以此方法來實現。
Step2. Enable Unix account authentication
Step3. 以debug mode啟動
先以debug mode啟動radius server看看是否能啟動成功:

………………. Message

如果看到Ready to process requests的話就代表成功了。
Note: 目前只允許localhost (127.0.0.1)可以連線,如果要允許別的網段或IP連線到本機認證的話請修改 /etc/raddb/clients.conf
Step4. 以本機使用者認證:
Usage: radtest

如果看到回應Access-Accept ……… 那麼就是代表認證成功。
Step6.以daemon方式啟動radius server,並測試:


成功的以daemon的方法啟動radius server,並且能正常工作。
Step1. 將啟動radius server的使用者改為root
# vi /etc/raddb/radiusd.conf
如果不這麼做的話,當啟動radius server時,由於radiusd user對於/etc/shadow沒有讀取的權限,故會發生permission denied。網路上有找到PAM Support for FreeRadius (http://www.sfr-fresh.com/unix/misc/freeradius-1.0.5.tar.gz:a/freeradius-1.0.5/doc/rlm_pam)的文章,可是照著做還是不能work,所以先以此方法來實現。
Step2. Enable Unix account authentication
# vi /etc/raddb/radiusd.confunix {
cache=yes
passwd= /etc/passwd
group=/etc/group
shadow=/etc/shadowradwtmp=${logdir}/radwtmp}
Step3. 以debug mode啟動
先以debug mode啟動radius server看看是否能啟動成功:

………………. Message

如果看到Ready to process requests的話就代表成功了。
Note: 目前只允許localhost (127.0.0.1)可以連線,如果要允許別的網段或IP連線到本機認證的話請修改 /etc/raddb/clients.conf
Step4. 以本機使用者認證:
Usage: radtest

Step6.以daemon方式啟動radius server,並測試:


Wednesday, July 23, 2008
Tcl + expect 簡單實作
這陣子在幫公司做些自動化測試的環境,故常利用到tcl搭配expect故在此做個雜記:
舉個簡單的例子,透過tcl與expect ssh login到遠端機器並將它reboot:
整個tcl的內容如下:
#!/usr/bin/tclsh
package require Expect
set ip [lindex $argv 0]
spawn ssh -o StrictHostKeyChecking=no Administrator@$ip
expect "Password: "
send "aaaa\r"
expect ">"
send "reboot\r"
expect "(y/n)"
send "y\r"
expect "# "
以expect期待得到怎樣的輸出後,便使用send輸入命令,而每台機器所吐出來的prompt都不相同,請自行更改。
執行: ./reboot.tcl 192.168.0.1
舉個簡單的例子,透過tcl與expect ssh login到遠端機器並將它reboot:
整個tcl的內容如下:
#!/usr/bin/tclsh
package require Expect
set ip [lindex $argv 0]
spawn ssh -o StrictHostKeyChecking=no Administrator@$ip
expect "Password: "
send "aaaa\r"
expect ">"
send "reboot\r"
expect "(y/n)"
send "y\r"
expect "# "
以expect期待得到怎樣的輸出後,便使用send輸入命令,而每台機器所吐出來的prompt都不相同,請自行更改。
執行: ./reboot.tcl 192.168.0.1
Subscribe to:
Posts (Atom)


