Linux 印出有顏色的程式碼

在 linux 環境只要印出程式碼來看,可以用 cat or less 這些檔案輸出的指令,

但是都沒有像 vim 一樣有顏色,可以先裝好 source-highlight 這個套件,yum 或 apt-get 應該都可以~

他原始碼裡面就有附一個用來 less 的 shell

#! @SHELL@

for source in $1; do
    case $source in
	*ChangeLog|*changelog)
        source-highlight --failsafe -f esc --lang-def=changelog.lang --style-file=esc.style -i $source ;;
	*Makefile|*makefile)
        source-highlight --failsafe -f esc --lang-def=makefile.lang --style-file=esc.style -i $source ;;
        *) source-highlight --failsafe --infer-lang -f esc --style-file=esc.style -i $source ;;
    esac
done

可以再整理成一個 shell 用來呼叫

#!/bin/bash

if [ "$1" = -h ]; then
	echo "usage : ccat $file"
elif [ $1 ] && [ -f $1 ]; then
	src-hilite-lesspipe.sh $1 |less -R
else
	echo 'no input '
fi

然後就能用 ccat $file 印有顏色的程式出來看哩

參考資源:

fedora vnc

內建有簡易的 gui 管理介面的遠端桌面伺服器是 vino-server port 是 5900,qemu-vnc 的 port 也是從 5900 開始,不知道去哪改。

fedora 內建的 xrdp 沒有像 ubuntu 在 /etc/xrdp/xrdp.ini 裡面有一堆設定,只有預設的 session man ,他會一直開 session 。。而且不能指定你要登入哪個 session,所以我灌了一個 x11vnc 來跑本地畫面的 vnc ,藉由 libvnc.so 來轉介 vnc 服務,猜是安裝 vnc4server 以後才有的。

然後透過 xinetd 來自動啟動 x11vnc。

service x11vnc
{
flags = REUSE NAMEINARGS
port = 5950
type = UNLISTED
socket_type = stream
protocol = tcp
wait = no
user = root
server = /usr/sbin/tcpd
server_args = /usr/local/bin/start_x11vnc
disable = no
}
#!/bin/sh

authfile=`ps wwaux | grep '/X.*-auth' | grep -v grep | sed -e 's/^.*-auth *//' -e 's/ .*$//' | head -n 1`

if [ -r "$authfile" ]; then
exec /usr/bin/x11vnc -inetd -o /var/log/x11vnc.log -display :0 -auth "$authfile" -many -bg -xkb -ultrafilexfer -users mlwmlw -rfbauth /home/mlwmlw/.vnc/passwd -noxrecord

fi
exit 1

幫 xrdp 加入一個新的項目,這樣就可以用 window reomote client 連哩

[screen]
name=console
lib=libvnc.so
username=n/a
password=ask
ip=127.0.0.1
port=5950

參考資料:

Fedora KVM Networking

這幾天在自己電腦上安裝了 fedora 15 除了感受一下 gnome3 嶄新的使用者界面外,

順便也玩一下整合很完整的 KVM,用 dvd 裝完以後有勾選虛擬化,就會把相關軟體一次都裝好了(kvm,qemu,libvirtd…) ,只要透過虛擬機管理員就可以輕鬆的建立 vm,並且使用了~感覺很愜意呢~

只是想要瞭解他相關網路的設定,好像就沒有很簡單了…原本網路概念就有一點模糊,順便重新整理自己網路的知識… Continue reading…

Curl 上傳檔案

Curl 一種文字介面的 Web Client,有 shell 的版本跟 lib 的版本,被廣泛應用在很多語言的 lib 上。

官方網站:http://curl.haxx.se

有原始碼、文件等等資料可以瀏覽跟下載。

最簡單的使用方式 例如:

$ curl http://mlwmlw.org

他就會回傳這個網站的 html 直接輸出到 stdout,甚至還能 POST DATA(FILE)
在 7.18 以後支援 –data-urlencode 這個參數,可以傳檔案並且指定 post name。

$ curl http://mlwmlw.org --data-urlencode file@httpd.conf

他原本的用法就是 @檔案名稱,就能指定要上傳的檔案了,現在加上 at 前面可以指定 POST 的 field name。

不然一般情況就用 -d @file.txt 就可以了

如果要搭配一些傳輸的時間資訊,可以加上 write-out 的參數,

$ curl -w '\nLookup time:\t%{time_namelookup}\nConnect time:\t%{time_connect}\nPreXfer time:\t%{time_pretransfer}\nStartXfer time:\t%{time_starttransfer}\n\nTotal time:\t%{time_total}\n'
   -o /dev/null --data-urlencode file@test.txt -s http://mlwmlw.org

如果要測試一些 rest 的 api 可以指定 method

curl -X POST http://mlwmlw.org -d "name=1&test=2"
curl -X GET http://mlwmlw.org
curl -X DELETE http://mlwmlw.org
curl -X PUT http://mlwmlw.org

在 windows 輸出空白可以用

$ curl.exe -w '...' -o NUL ...

參考資源: