好物,有不收藏的道理嗎?
2013年5月28日 星期二
2013年2月1日 星期五
常用 vi 密技之一
1. vim加上多行註解的步驟:
(1) 將游標移到要開始註解的那一列。
(2) 按下ESC、然後按下Ctrl + V ,切換成區塊選取的模式(就是反白啦)。
(3) 將游標向下移到要加上註解的最後一列,此時你可以發現這幾列都被反白了。
(4) 按下大寫I,游標跑回步驟(2)的那一列了,這時就可以直接輸入要用的註解了,假設輸入'//'。
(5) 按下ESC,大功告成。
(6) 千萬不要忘記步驟(5)。
2. vim 取消多行註解的步驟:
(1) 方法和加上多行註解一樣,先將游標移到開始註解的那一列。
(2) 按下ESC、然後按下Ctrl + V ,切換成區塊選取的模式。
(3) 將游標向下移到要加上註解的最後一列,再按左、右的方向鍵,將要delete掉的註解都反白。
(4) 按下delete,大功告成。
其實vim中,Ctrl + V的區塊模式還有很多有趣的功能可以摸索。
其他進階功能,可以參考Vim的官方網站。
http://www.vim.org
2011年9月19日 星期一
Linux distribution
lsb_release,可列出cat /etc/issue與lsb_release去確認Linux distribution的結果
LSB Version: :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd....Distributor ID: CentOSDescription: CentOS release 5.4 (Final)Release: 5.4Codename: Final
2011年3月17日 星期四
UNIX 文字工具: pipe
UNIX 文字工具: pipe
UNIX 除了可以將資料流導入或導出純文字檔案之外, 還可以將它導向另一個工具軟體,或是濾器。 這個機制稱為導管 (pipe)。導管符號是 | (通常在鍵盤的 Shift+\ 位置)。 | 的功能就是將它左邊的 stdout 資料變成右邊的 stdin。 所以,只要一個工具軟體的輸出是 stdout, 一個工具軟體的輸入是 stdin,就可以用導管將它們銜接在一起, 變成一個新的工作流程 (pipeline)。例如
cat -n list.txt | less就是將加上列號的 list.txt 檔案,放進 less 閱讀工具中。再如
tail -12 list.txt | cat -n就是將 list.txt 的後 12列,加上列號,印在螢幕上。
只要合乎規定,UNIX 並不限定一個流程中可以使用幾次導管。例如您可以說
tail -22 list.txt | cat -n | less
如果您想要看到一個文字檔案從第 n 列到第 m 列的內容, 可以說
head -m FILE | tail -K其中 K = m - n + 1。
舉個特例。如果想看到 list.txt 的第 5 列,就說
head -5 forty.txt | tail -1
參考http://libai.math.ncu.edu.tw/bcc16/6/textutil/index.html
2011年3月11日 星期五
2010年3月10日 星期三
Shell 環境
例如,我們要將預設的文書編輯器改成 ee,
在 tcsh 中可以使用:
# setenv EDITOR ee如果您使用的是 Bourne Shell:# export EDITOR="ee"在 /etc 下的 csh.cshrc 是通用的設定,但如果使用者自己的設定和通用設定一樣時,會以使用者的設定為主。
如果您希望日後每個新增的使用者的設定都是這樣,則必須修改 /usr/share/skel/dot.cshrc 檔案
/etc/csh.cshrc 和 /etc/csh.login的差別在於如果是使用者登入,二個檔案都會被執行,如果是 scripts 則只會去讀取 csh.cshrc。
http://twbsd.org/cht/book/index.php?ch=03
相關資料:第十一章、認識與學習 BASH
2010年3月9日 星期二
安裝php5 on FreeBSD8
# make config
# make install
Once php has installed you will need to install the extra modules for things such as MySQL. These modules are all located in the ports. Some of the most common modules are
/usr/ports/databases/php5-mysql - MySQL Database /usr/ports/www/php5-session - Sessions /usr/ports/graphics/php5-gd - Graphics Library
Adding the PHP 5 module to Apache
Apache needs the following lines in the httpd.conf file to use php. These lines should already be added by the port but if you have problems you should double check your httpd.conf file. Note that Apache 2.x does not need the AddModule line.# Apache 1.3.x LoadModule php5_module libexec/apache/libphp5.so AddModule mod_php5.c
# Apache 2.x LoadModule php5_module libexec/apache/libphp5.soIf you installed using the port and had apache installed already it should do this automatically for you.
Next find your DirectoryIndex section in your httpd.conf file. Apache is set up for PHP 4, but not PHP 5 currently so you will need to modify it and change the 4s to 5s like this.
You can change the order as you wish. Or if you just wanted to skip it you could simply add the following line to the httpd.conf file since you know you are going to have php 5.
DirectoryIndex index.php index.html index.htmNow apache just needs to know what it should parse the PHP files with. These two lines should be added to the httpd.conf file, and can be put at the bottom if needed.
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phpsIf want to use PHP code inside of .htm files you can just add on those extensions.
AddType application/x-httpd-php .php .htm .html
Configuring PHP
Settings for PHP are stored in /usr/local/etc/php.ini You will need to create this file by copying it from /usr/local/etc/php.ini-dist# cp /usr/local/etc/php.ini-dist /usr/local/etc/php.ini In this file you can set the memory limit for programs. Turn on global variables if you must, set the max file upload size, and everything else you need.
From:http://www.freebsdmadeeasy.com/tutorials/web-server/install-php-5-for-web-hosting.php
2009年9月10日 星期四
LDAP安裝筆記
cvsup -g -L 2 /root/ports-supfile
#ports-all
ports-net
ports-devel
ports-security
error log:
openldap-sasl-server cannot install: unknown LIBTOOL version: 22
根據失敗的訊息發現部分相依程式版本不對,再根據該程式的目錄去做 cvsup
基本上 make reinstall應該就可以順利安裝
===> An older version of net/openldap23-server is already installed (openldap-server-2.3.43)
You may wish to ``make deinstall'' and install this port again
by ``make reinstall'' to upgrade it properly.
If you really wish to overwrite the old port of net/openldap23-server
without deleting it first, set the variable "FORCE_PKG_REGISTER"
in your environment or the "make install" command line.
#make install FORCE_PKG_REGISTER="yes"
error log:(我決定裝現在最新版本OpenLDAP24)
OpenLDAP versions mismatch: openldap23-client is installed
最後把23版重新再裝一次然後再deinstall
openldap23-server #make reinstall
openldap23-server #make deinstall
openldap24-server #make install
最後終於成功可以裝24版
2009年6月30日 星期二
強迫密碼變更時間
#pwd_mkdb master.passwd
- master.passwd 這個檔案內容中,每個使用者都是獨立的一行,每個欄位使用冒號分開,它的格式是:
name:password:UID:GID:class:change:expire:fullname:home:shell
- change:強迫使用者變更密碼的時間,以從1970年到所要變更日期所經過的秒數來表示。你可以使用 date +%s 來求出從1970年到現在時間所經過的秒數,每天為86400秒,以現在時間的秒數加上86400*天數即為你要設定的時間。你可以使用指令下列指令來取得30天後的秒數,再將其填入即可。若設為0則表示不使用此功能:
# expr `date +%s` + 86400 \* 30
2009年5月25日 星期一
用 FreeBSD 來存取 MS Windows 的網芳資料
mount_smbfs -I 192.168.1.2 -N '//NetBISO/shareDirectory' /mnt/abc
這裡的參數 I 表示指定 IP 位址,參數 N 表示不須密碼驗證。如果您所要掛入的分享資料夾需要密碼認證,則不要加參數 N。我們在掛入別台電腦的資料夾時,如果沒有指定使用者名稱,內定會以目前所使用的帳號。
如果我們要使用別的使用者名稱,可以使用下列方式:# mount_smbfs -I 192.168.0.2 '//username@電腦名稱/shareDirectory' /mnt
要掛入的分享目錄:shareDirectory
掛入系統中哪一個目錄:/mnt/abc
This example assumes that a CIFS share has been mounted on the /mnt mount point. The following command line unmounts the share from the mount point.
# umount /mnt
2009年4月28日 星期二
Radius帳號設定
- 設定 radiusd.conf:因為使用者帳號存在檔案中,因此要確認 authorize 檔中的 file 這個屬性不能被 mark 起來(將#符號取消)
- 由於是在本機端認證,因此不需要修改 proxy.conf
- 在users中加入下列幾行:
Reply-Message = "Hello World!"
設定完成之後,要如何確定設定是否正確呢?可以利用 radtest 這個指令,其格式為 radtest [帳號] [密碼] [認證位址:認證埠] [NAS port] [secret key]:
[root@localhost ~]# radtest user pass localhost 0 testing123
Sending Access-Request of id 75 to 127.0.0.1 port 1812
User-Name = "user"
User-Password = "pass"
NAS-IP-Address = 255.255.255.255
NAS-Port = 0
rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=75, length=57
Reply-Message = "Hello World!"
本篇轉錄自經濟部工業局
2009年4月14日 星期二
Apache 裡 index of 的亂碼問題
想開放一個資料夾,讓老師能透過 samba 上傳教學資料,且在上傳後直接在網頁上就可瀏覽,
若網頁為 big5,中文字在瀏覽器中會變成亂碼,必須要加入以下這行才能解決:
IndexOptions Charset=big5
完整的設定如下,在 httpd.conf 加入中加入
IndexOptions Charset=big5
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
#另外測試用不同瀏覽器發現存檔的時候有差異
- FireFox存檔時中文正常
- IE存檔時仍是亂碼
2009年4月12日 星期日
2009年4月11日 星期六
multi IP應用 on FreeBSD
- 只有一台主機及一張網卡
- Public IP:公開的網站
- 一個 Private IP:內部網站
應用範圍
- Setup 2 or More IP address on One NIC
- ifconfig -alias
ifconfig_lnc0_alias0="192.168.1.5 netmask 255.255.255.255"(/etc/rc.conf) - Finally, Restart FreeBSD network service using network restart script:
# /etc/rc.d/netif restart && /etc/rc.d/routing restart
- ifconfig -alias
- Apache - VirtualHost 架設虛擬網站
2009年4月8日 星期三
登入...就馬上寄信給特定的帳號
想攔截也都來不及...這樣才知道對方什麼時後來的...以及從那裡來...相信這些資訊對被Hack的一方很有用..因為厲害的Hack會把所有可查的記錄檔全部清掉...讓你無從查起...試試看這個...很好用的..
(1)編輯 /etc/profile 在最後一行加入底下語法:
NOW=`date +%Y%m%d:%H%M%S`
LAST=`last $USER -5`
echo "[$NOW]: From $HOSTNAME : this user $USER login..." > /tmp/userlogin.log
echo "$LAST" >> /tmp/userlogin.log
mail -s "Attention !! User Login~~" user1@test.com,user2@test.com < /tmp/userlogin.logrm -f /tmp/userlogin.log
# Nice from http://dz.adj.idv.tw/redirect.php?tid=27&goto=lastpost&sid=jKGOzj
2009年3月24日 星期二
aliases.db out of date
> hi
>
> i cvsup'd a few days ago to 4.8 from 4.7
> ever since, i've been receiving the following message repeatedly in root's email security reports
> Apr 17 15:00:01 xhostname sm-mta[58360]: alias database /etc/mail/aliases.db out of date
>
> how did this happen?
You updated /etc/mail/aliases, probably by running mergemaster, but
you didn't regenerate the aliases.db file from the aliases file -- and
it's aliases.db being older than aliases which sendmail is complaining
about.
Fix is simple. Just run:
# newaliases
Cheers,
Matthew
--
Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks
Savill Way
maillog 分析
透過 Unix-like 常見的指令或是強大的 perl 來作進行 log 檔的分析。底下有幾個簡單的例子。
查詢伺服器收了幾封信件?
$ grep "from=" /var/log/maillog | wc -l
查詢記錄檔中的某些日期的郵件數量,例如 Oct 11
$ grep "Oct 11" /var/log/maillog | grep "from="| wc -l
查詢某使用者的某封信件狀況
$ grep "xxx@mail.net" /var/log/maillog
Oct 11 00:08:31 shona sendmail[28590]: [ID 801593 mail.info] j2VG8UoI028560: to=, delay=00:00:01, xdelay=00:00:00, mailer=relay, pri=121310, relay=[10.115.1.15] [10.115.1.15], dsn=2.0.0, stat=Sent (j2VG8RjQ013936 Message accepted for delivery
接著利用 Message-ID 做搜尋
$ grep "j2VG8UoI028560" /var/log/mail
Oct 11 00:08:30 shona sendmail[28560]: [ID 801593 mail.info] j2VG8UoI028560: from=, size=1310, class=0, nrcpts=1, msgid=<20051011160826.3451.qmail@mail.fakeurl.net>, proto=SMTP, daemon=MTA, relay=mail.fakeurl.net [192.168.20.15]
Oct 11 00:08:31 shona sendmail[28590]: [ID 801593 mail.info] j2VG8UoI028560: to=, delay=00:00:01, xdelay=00:00:00, mailer=relay, pri=121310, relay=[10.115.1.15] [10.115.1.15], dsn=2.0.0, stat=Sent (j2VG8RjQ013936 Message accepted for delivery)
可得知該封信件寄出成功r
如果想要得到較完整豐富的分析,可以寫個 perl 程式來作處理,網路上也許多免費軟體或收費商業軟體可使用。
免費軟體
SMA - Sendmail log analyzer (written in C, for Sendmail)
sendmail_stat (written in C, for Sendmail)
pflogsumm (written in perl, for Postfix)
eximstats (for exim)
商業軟體
Sawmill ( supports 600 different log formats)
本篇參考http://enews.cc.ncu.edu.tw/enews/post_view2.php?unit=1&sn=155
2009年2月18日 星期三
sed
sed -i.bak s/e/o/g foo
And you'll get a backup of the original in a file name 'foo.bak', but if you want no backup:
sed -i '' s/e/o/g foo
2009年2月17日 星期二
unix密碼檔格式
master.passwd@FreeBSD帳號:密碼:UID:GID:Login Class:Change:Expire:Full Name:家目錄:Login SHELL
- Login Class:幾乎沒在用了,通常是空的
- Change:強迫使用者改密碼的時間週期, 0 表示不設定
- Expire:使用者帳號的使用期限, 0 表示不設定
passwd@Linux帳號:密碼:UID:GID:Full Name:家目錄:Login SHELL
FreeBSD比Linux多了三個欄位
因為Linux的密碼是存在shadow
在 FreeBSD 中和使用者帳號資訊相關的有下面幾個檔案
/etc/master.passwd 和 /etc/passwd 是我們一般所謂的密碼檔,這兩個檔案都是以純文字的方式儲存,當我們以文書編輯軟體開啟檔案時可以直接看到記錄的內容,不過,FreeBSD 為了提昇讀取使用者資訊的效能,真正使用的是轉換為 db 格式的資料庫檔 /etc/pwd.db 和 /etc/spwd.db 。
熱門文章
-
昨天廠商在教育訓練時被我發現有熟悉的圖案發現,經詢問果然是久違的版本控制-subversion,又讓我燃起對它的興趣,總覺得一定可以搞出個甚麼東西,至少在應用上是一個很棒的工具 http://subversion.tigris.org/ http://twpug.net/do...
-
不僅適用於程式開發,也適用於檔案文件管理~nice http://www.openfoundry.org/component/option,com_docman/Itemid,1/gid,956/task,doc_details/ 很詳細的中文介紹文件-* http://...
-
https://docs.microsoft.com/zh-tw/azure/expressroute/expressroute-asymmetric-routing Asymmetric routing with multiple network path 越來越多的網路環...