-->

Tuesday, February 07, 2012

Change kopete status message "now listen to" by audacious

For complex reasons, I use RHEL 6 for daily work/play Linux distro. And it's well know WONTFIX bug: lack of webkit for kdelibs cause Amarok not compilable. So I switch to Audacious.

This is how I use Audacious to change my kopete status message for "now listen to":


1. Enable "Song Change" plugin in "General" plugins catalog.

2. Put this command into "Command to run when Audacious starts a new song"
qdbus org.kde.kopete /Kopete org.kde.Kopete.setIdentityOnlineStatus "" "♫ %T - %a"

3. It will work like charm.


Thursday, November 24, 2011

Veer for Linux Geek

It's a long story to get hands on Veer. Call me if you want to know.
As the successor of my previous N900, it takes some time to tune it up for
Linux Geek like me.

1. Linux platform is supported by HP now. Only 1 package needed (I take
   Chakra as an example):
   palm-novacom: http://chakra-linux.org/ccr/packages.php?ID=2526

   Once you enable "Developer Mode" [1], veer will have a daemon called
   "novacomd" which communicate with your Linux Box's novacomd

   After veer reboot to developer mode, you can get a root shell via
    "novaterm" via USB cable after both novacomd started.

   Install preware by following this pages.

   Install "openssh-sftp-server openssh" in optware section of preware.

   Use vi in novaterm to create "authorized_keys":
   =====
root@GrisGesHPVeer:~# mkdir /home/root/.ssh/
root@GrisGesHPVeer:~# vi /home/root/.ssh/authorized_keys
   =====
   For better login experience, I add my user name as a shadow of root:
   =====
root@GrisGesHPVeer:~# tail -1 /etc/passwd
fge::0:0:root:/home/root:/opt/bin/bash
   =====

   Now, Install "bash perl vim":
   ====
root@GrisGesHPVeer:~# ipkg-opt install vim perl bash
   ====

2. Rsync for my music.
   a. Install rsync on both your Linux and veer:
   ====
[fge@Gris-Laptop ~]$ sudo pacman -S rsync
   ====
root@GrisGesHPVeer:~# ipkg-opt install rsync
   ====
   b. Change my code for your Music folder: #I only sync my podcast folder.
   ====
[fge@Gris-Laptop ~]$ cat bin/veer_sync
#!/bin/bash
if [ "CHK$(ifconfig eth0 |grep "inet addr:10.66")" != "CHK" ]; then
# I check whether I am in office or not. As this script will goes to cron
# Check before sync is important.
    rsync --compress --archive --delete  -e ssh  \
        /media/private/Music/podcasts \
        gris-veer:/media/internal/Music/ 2>/dev/null
fi
# Note, you might have chgrp error from rsync without "2>/dev/null"
# Try your google to find why if you care.
   ====
  c. Add this code into cron:
   ====
[fge@Gris-Laptop ~]$ sudo ln -s /home/fge/bin/veer_sync \
    /etc/cron.daily/veer_sync
   ====

3. I don't want to type any command on veer via it's keybroad. But if you want,
   Use SDL Terminal or Terminus.

4. Disable "Voice Dial"
   ====
root@GrisGesHPVeer:~# luna-send -n 1 \
  palm://com.palm.systemservice/setPreferences '{"enableVoiceCommand":false}'
root@GrisGesHPVeer:~# reboot
   ====

5. Remove whatever ssytem package you hate in your veer.
   ====
root@GrisGesHPVeer:~# ipkg list_installed | less
root@GrisGesHPVeer:~# ipkg remove amazonservice attwisprd \
  com.palm.app.amazonstore com.palm.app.attsyncpanel \
  com.palm.app.minidm com.palm.app.mobilehotspot \
  com.palm.attaddresssync com.telenav.attnavigation \
  com.yellowpages.ypmobile.preload \
  contacts.plugin.pmvoicecommand minidm \
  pmvoicecommand-enus pmvoicecommand-esmx \
  pmvoicecommand
   ====

6. Disable "Developer Mode" as we have openssh now.

Monday, November 07, 2011

Force review email before send out in vim

It happens a lot that I regret for the misspellings right after I send out the email. So I force myself to review the email before vim quit to mutt. Here is the what I put into my vimrc:
 1 "Sleep 20s before quit when edit email
 2 autocmd VimLeavePre /tmp/mutt* echo 'Slow down, you have 20 seconds to '
 3                                  \. 'review this email'
 4 autocmd VimLeavePre /tmp/mutt* sleep 20

Tuesday, September 13, 2011

Using vpnc with dnsmasq

You may say "try the WTF resolvconf", but I am an old-school guy who hate grub2 and resolvconf a lot.

Just simply add this line into your default.conf (or any other name) of vpnc
Script INTERNAL_IP4_DNS="127.0.0.1 <ISP and VPN DNS>" /etc/vpnc/vpnc-script
Please change <ISP and VPN DNS> into your DNS entries. If you still ask why we put ISP DNS ahead or why we need 127.0.0.1, you are not the target reader of this page.


As "man 7 vpnc" already said:
The vpnc daemon by itself does not set any routes,
but it calls vpnc-script to do this job.
You can write your own script for maintaining the DNS resolv.conf and Route table.
For me, this hard-coded way above already save my life.
Hope this could help you. Updates: I noticed China Unicom DNS Server has DNS HiJack (Actually, most China ISP do this), dnsmasq results will got incorrect for my Corp DNS entry. So here the solution: add these lines into your /etc/dnsmasq.conf
no-resolv
no-poll
server=208.67.222.222 #openDNS
server=/redhat.com/10.66.127.10
And also, you need change your vpnc.conf back to:
Script INTERNAL_IP4_DNS="127.0.0.1 <VPN and ISP DNS>" /etc/vpnc/vpnc-script

Friday, August 19, 2011

Auto login via ssh and change konsole tab name accordingly

I have tons of servers need ssh login and some can't tell reason prevent me from password-less RSAAuthentication. So here the codes.
 1 #!/bin/bash
 2 EXP_CODE_PATH="/home/fge/bin/rss.exp"
 3 SER="$1"
 4 if [ "CHK${SER}" == "CHK" ];then
 5     echo "FAIL: Need specify a server name or ip as \$1"
 6     return 1
 7 fi
 8 
 9 #remove key item from .ssh/known_hosts
10 sed -i '/^'"${SER}"'/d' ~/.ssh/known_hosts 1>/dev/null
11 IP_ADDR=`ping "${SER}" -c 1 -w 0.1 \
12     | perl -ne 'print $1 if/PING.+\(([0-9]+\.[0-9\.]+)\)/'`
13 sed -i '/'"${IP_ADDR}"'/d' ~/.ssh/known_hosts 1>/dev/null
14 
15 #Setup tab name of konsole
16 CURR_SE_ID=$(qdbus org.kde.konsole /Konsole \
17     org.kde.konsole.Konsole.currentSession)
18 PRE_TAB_FORMAT="$(qdbus org.kde.konsole /Sessions/${CURR_SE_ID} \
19     org.kde.konsole.Session.tabTitleFormat 0)"
20 qdbus org.kde.konsole /Sessions/${CURR_SE_ID} \
21     org.kde.konsole.Session.setTabTitleFormat 0 "" 1>/dev/null
22 qdbus org.kde.konsole /Sessions/${CURR_SE_ID} \
23     org.kde.konsole.Session.setTitle 0 "Remote: ${SER/.*/}" 1>/dev/null
24 qdbus org.kde.konsole /Sessions/${CURR_SE_ID} \
25     org.kde.konsole.Session.setTitle 1 "Remote: ${SER/.*/}" 1>/dev/null
26 
27 
28 #call ssh
29 ${EXP_CODE_PATH} ${SER}
30 
31 qdbus org.kde.konsole /Sessions/${CURR_SE_ID} \
32     org.kde.konsole.Session.setTabTitleFormat 0 "${PRE_TAB_FORMAT}" \
33     1>/dev/null
34  
 
rss.exp (expect code):

 1 #!/usr/bin/expect --
 5 set server [lindex $argv 0]
 6 set passwd "123456"
 7 set command ""
 8 set timeout 60
 9 
10 #log out other session as netapp only support 1 active session
11 spawn ssh root@$server
12 match_max 100000
13 expect {
14     "yes/no" {
15         send "yes\n"
16         exp_continue
17     }
18     "assword:" {
19         send "$passwd\n";
20         interact
21     }
22 }

Thursday, August 04, 2011

Remove white space and restore cursor location in vim



 1 "auto remove whitespace at the end of line before :w,
 2 "it also save email signiture spliter "-- "
 3 function s:RemoveWhiteSpace()
 4     let save_cursor = getpos(".")
 5     %s/\s\+$//e
 6     if &filetype == 'mail'
 7         %s/^--$/-- /e
 8     endif
 9     call setpos(".", save_cursor)
10 endfunction
11 autocmd BufWritePre * :call <SID>RemoveWhiteSpace()

Those codes will save your current cursor location and remove all white spaces when you kickoff ":w", cursor location will be restored once done.
As email signature spacer separator is "-- " which should ignore by white space removal. Don't know why email keep white space for it.

PS: If you wonder how I handle code syntax highlight in blogger, try vim command: "TOhtml" and copy style, pre sections into blogger during edit html. You might also need to setup colorscheme in vim for colorfully html.
I still have difficulty in exporting my konsole colorscheme into vim. My vim only looks good when using default color scheme in vim and follow the rule of konsole color scheme. Anyway, what you look in this blog is not the same in my vim, so don't blame on my bad taste.

Wednesday, June 01, 2011

误删部分Gtalk好友

NuevaSync把我N900中联系人全部弄重复了(Nokia换电池,然后时间reset, 最后active sync自动同步本地优先)。

contact de-duplication的程序把重复部分删除,伟大的maemo以为我要求删除关联gtalk和msn联系人。
其心情莫过于 echo c | sudo tee /proc/sysrq-trigger
请在试上面那个命令前,保存你的文件。

请受影响的同学在Gtalk或/和MSN中,重新添加好友。
获取我的邮箱地址需执行如下代码或者HOWTO.
Perl愤青:

perl -e 'print pack("H*","636e666f75727440676d61696c2e636f6d")'

Python2 和 Python3 愤青:
python -c "import binascii;print(binascii.a2b_hex(b'636e666f75727440676d61696c2e636f6d'));"
其他愤青:
请安排可信任的Perl和Python愤青处理。貌似术语叫Management By Delegation
其他:
echo c | sudo tee /proc/sysrq-trigger

就这样,大家翻墙辛苦了。

Friday, March 05, 2010

Perl scripting on N900


I just noticed that it could be more effective if I wrote scripts on my Cellphone rather than PC.

1. Installing software we need (The Perl shipped with N900 is 5.8.3 and do not contain the perl-modules. Please enable SDK repo to install the whole perl).
apt-get install bash vim


2. Change the enviroment.
1) bash
Change /etc/passwd first as root to let "user" got bash as default shell.
As x-term start a bash in non-interactive mode. So we need edit .profile file to change PS1 and enable the colorful ls output.
PS1='[\u@\W]\$ '
umask 022

2) vim
vim .vimrc
set nu
set expandtab
set tabstop=4
set softtabstop=4
set shiftwidth=4
syntax on
filetype plugin off
filetype indent off
set grepprg=grep\ -nH\ $*
set shellslash
set mouse =
set nohlsearch
set noincsearch
set tw=0
set formatoptions=l
set lbr

3. Enable FN + Arrow to input {} and []
Replace the last closure of /usr/share/X11/xkb/symbols/nokia_vndr/rx-51 as below:
xkb_symbols "arrows_4btns" {
key { type[Group1] = "PC_FN_LEVEL2", symbols[Group1] = [ Up, braceleft ] };
key { type[Group1] = "PC_FN_LEVEL2", symbols[Group1] = [ Left, bracketleft ] };
key { type[Group1] = "PC_FN_LEVEL2", symbols[Group1] = [ Down, braceright] };
key { type[Group1] = "PC_FN_LEVEL2", symbols[Group1] = [ Right, bracketright ] };
};

If you want to ues another key instead of [] and {}. Please check http://cgit.freedesktop.org/xkeyboard-config/tree/symbols/us for the keyname.

4. Modify the softkey in the x-term as this picture:

Just execute the following commands as user account in shell:
gconftool-2 -s /apps/osso/xterm/keys \
-t list --list-type=string \
"[Tab,Escape,bar,greater,dead_grave,percent,dead_tilde]"
gconftool-2 -s /apps/osso/xterm/key_labels \
-t list --list-type=string "[Tab,Esc,|,>,\`,%,~]"

If you want to ues another key. Please check http://cgit.freedesktop.org/xkeyboard-config/tree/symbols/us for the keyname.

Friday, February 26, 2010

Nokia N900入手记录

手机是改的Debian的系统,很顺手。没心去论坛教哪些Windows用户,故发布心得笔记如下:

1. 公司的VPN也搞定了:装vpnc和vpnc-gui和iproute一切就OK了。装iproute的原因是/etc/vpnc/vpnc-script脚本没写好。其中虽然考虑到若没有"ip"命令时使用"route"这个命令,但route命令参数错了,我懒得折腾就直接装了个iproute省心。我老板说,这下可以时刻收邮件了,我说邮件下班后坚决不看,只看有土鳖(youtube)和非死不可(facebook)。

2. 虽然自带Flash,但貌似是9的版本,不支持硬件渲染。能够基本流畅的播放youku的电影,但youtube的720p很吃力。自带的浏览器虽不错,但不支持Google Reader的快捷键,这是一个问题。

3. Mozila新发布的Firefox(叫Fennec),没Flash,且占用rootfs 20MB+,装上后就删了。

4. 有人建议装什么rootsh这个软件,实际上只是改sudoers文件而已的把戏。我直接写了个程序叫a,放/bin/下,然后设suid为0。每次提权输入个a就搞定,方便快捷。

5. Ovi地图飘移的严重,大概300米的样子。忍了。难得管,

6. 没Google Latitude,源里虽有一个可以更新Location的软件,但貌似无效。

7. N900有qt4.6, bash, Perl 5.8.8, GCC 4, make, vim。基本顺手,但键盘上没"pipe"这个键严重影响敲命令效率。准备把basket改写成qt版的。

8. 不喜欢入耳式耳机,特别是在上海这风大的城市里。

Saturday, May 09, 2009

笔记本硬盘更换记(使用LVM进行在线数据迁移)

前言:终于买了个160G的硬盘来更换我那古董级的硬盘了。多谢LVM,现在可以一边写本文,一边在进行硬盘数据的切换。

提前约定:
  1. 数据操作较危险,请完全理解LVM知识和术语后部署。
  2. 原始的笔记本硬盘已经被取出,并作为移动硬盘使用USB和笔记本连接。系统将其识别为/dev/sdb,其中包含完整的Linux系统,除boot分区单独外,其他分区全部位于LVM中。
  3. 新的笔记本硬盘已经安装到笔记本中,被系统识别为/dev/sda,无任何数据。
  4. 全部命令默认使用root权限执行,并在Kubuntu 9.04上测试通过。
boot分区数据迁移步骤和前期准备:
  1. 使用USB启动,进入系统。修改GRUB的启动项,使用USB的移动硬盘启动进入Linux。系统和GRUB如果未使用UUID,可能需要进行适当修改,具体情况不在本文讨论范围内,可直接发邮件问我。
  2. 使用fdisk -l确定各个硬盘的分区表状态。得知sda是新硬盘,无分区表信息,sdb是旧硬盘。
  3. 使用fdisk /dev/sda创建新硬盘的分区表,并使用t命令将LVM分区的ID值修改为8e。最后的fdisk -l输出结果如下:Disk /dev/sda: 160.0 GB, 160041885696 bytes
    240 heads, 63 sectors/track, 20673 cylinders
    Units = cylinders of 15120 * 512 = 7741440 bytes
    Disk identifier: 0x50d050d0

    Device Boot Start End Blocks Id System
    /dev/sda1 * 1 2774 20971408+ 7 HPFS/NTFS
    /dev/sda2 2775 5549 20979000 a5 FreeBSD
    /dev/sda3 5550 5689 1058400 83 Linux
    /dev/sda4 5690 20673 113279040 8e Linux LVM

    Disk /dev/sdb: 60.0 GB, 60022480896 bytes
    255 heads, 63 sectors/track, 7297 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Disk identifier: 0x000797e0

    Device Boot Start End Blocks Id System
    /dev/sdb1 * 1 31 248976 83 Linux
    /dev/sdb2 32 7297 58364145 8e Linux LVM
  4. 首先应将/boot分区的数据复制到新的硬盘中,即/dev/sdb1到/dev/sda3的复制。使用mkfs.ext3 /dev/sda3创建分区表,然后mount /dev/sda3 /mnt,然后使用 cp -av /boot/* /mnt/ 命令复制数据。当然也可以使用dd命令直接复制硬盘分区(不推荐)。
  5. 使用vol_id --uuid /dev/sda3得到185b0052-1147-41c1-80c4-83f39c808c6d,然后将/mnt/boot/grub/menu.lst中的原UUID替换,最后替换/etc/fstab中的UUID。
  6. 尝试umount /boot 然后再mount -a 测试新的boot分区数据。
LVM数据迁移步骤:
  1. 创建物理卷:pvcreate /dev/sda4若当初使用了特殊的physicalvolumesize,请使用--setphysicalvolumesize选项。切记PV和LV的大小必须一致,默认是32MB。
  2. 将物理卷添加到正在使用的卷组FourT:vgextend FourT /dev/sda4
  3. 使用pvdisplay -m查看物理块分配情况。得到如下信息 --- Physical volume ---
    PV Name /dev/sdb2
    VG Name FourT
    PV Size 55.66 GB / not usable 4.24 MB
    Allocatable yes (but full)
    PE Size (KByte) 32768
    Total PE 1781
    Free PE 0
    Allocated PE 1781
    PV UUID O0VAmw-8M5T-Ek2g-AtMO-jDeR-xvPm-OQusKE

    --- Physical Segments ---
    Physical extent 0 to 319:
    Logical volume /dev/FourT/fsroot
    Logical extents 0 to 319
    Physical extent 320 to 479:
    Logical volume /dev/FourT/Private
    Logical extents 640 to 799
    Physical extent 480 to 1119:
    Logical volume /dev/FourT/Private
    Logical extents 0 to 639
    Physical extent 1120 to 1279:
    Logical volume /dev/FourT/home
    Logical extents 0 to 159
    Physical extent 1280 to 1748:
    Logical volume /dev/FourT/Others
    Logical extents 0 to 468
    Physical extent 1749 to 1780:
    Logical volume /dev/FourT/swap
    Logical extents 0 to 31

    --- Physical volume ---
    PV Name /dev/sda4
    VG Name FourT
    PV Size 108.03 GB / not usable 32.06 MB
    Allocatable yes
    PE Size (KByte) 32768
    Total PE 3456
    Free PE 3456
    Allocated PE 0
    PV UUID Os3abz-5zRI-LRfN-iaUF-ZaAr-gVUY-okAF3L

    --- Physical Segments ---
    Physical extent 0 to 3455:
    FREE
    根据上述信息可知:新的硬盘已经被添加到卷组中,并且空余3456块,大于已经使用的1781块,可以执行在线数据迁移。
  4. 停止对sdb2的物理块新增分配:pvchange -xn /dev/sdb2这样sdb2这个物理卷将不再接受新的数据块分配请求(和文件系统中文件增删无关)。
  5. 将旧硬盘上的块移动到其他硬盘上:pvmove -i 10 /dev/sda2-i参数是要求 10秒汇报进度,-d参数可将log发送到syslog。在此其间,pvdisplay -m得到如下信息:--- Physical volume ---
    PV Name /dev/sdb2
    VG Name FourT
    PV Size 55.66 GB / not usable 4.24 MB
    Allocatable NO
    PE Size (KByte) 32768
    Total PE 1781
    Free PE 0
    Allocated PE 1781
    PV UUID O0VAmw-8M5T-Ek2g-AtMO-jDeR-xvPm-OQusKE

    --- Physical Segments ---
    Physical extent 0 to 319:
    Logical volume /dev/FourT/pvmove0
    Logical extents 0 to 319
    Physical extent 320 to 479:
    Logical volume /dev/FourT/pvmove0
    Logical extents 960 to 1119
    Physical extent 480 to 1119:
    Logical volume /dev/FourT/pvmove0
    Logical extents 320 to 959
    Physical extent 1120 to 1279:
    Logical volume /dev/FourT/pvmove0
    Logical extents 1120 to 1279
    Physical extent 1280 to 1748:
    Logical volume /dev/FourT/pvmove0
    Logical extents 1280 to 1748
    Physical extent 1749 to 1780:
    Logical volume /dev/FourT/pvmove0
    Logical extents 1749 to 1780

    --- Physical volume ---
    PV Name /dev/sda4
    VG Name FourT
    PV Size 108.03 GB / not usable 32.06 MB
    Allocatable yes
    PE Size (KByte) 32768
    Total PE 3456
    Free PE 1675
    Allocated PE 1781
    PV UUID Os3abz-5zRI-LRfN-iaUF-ZaAr-gVUY-okAF3L

    --- Physical Segments ---
    Physical extent 0 to 319:
    Logical volume /dev/FourT/pvmove0
    Logical extents 0 to 319
    Physical extent 320 to 959:
    Logical volume /dev/FourT/pvmove0
    Logical extents 320 to 959
    Physical extent 960 to 1119:
    Logical volume /dev/FourT/pvmove0
    Logical extents 960 to 1119
    Physical extent 1120 to 1279:
    Logical volume /dev/FourT/pvmove0
    Logical extents 1120 to 1279
    Physical extent 1280 to 1748:
    Logical volume /dev/FourT/pvmove0
    Logical extents 1280 to 1748
    Physical extent 1749 to 1780:
    Logical volume /dev/FourT/pvmove0
    Logical extents 1749 to 1780
    Physical extent 1781 to 3455:
    FREE

  6. 当pvmove结束后(我这里收到ABORTING: Can't find mirror LV in FourT for /dev/sdb2的警告,但我并没有mirror LV,故忽略)。使用pvdisplay -m查看块分配情况,得到如下信息:--- Physical volume ---
    PV Name /dev/sdb2
    VG Name FourT
    PV Size 55.66 GB / not usable 4.24 MB
    Allocatable NO
    PE Size (KByte) 32768
    Total PE 1781
    Free PE 1781
    Allocated PE 0
    PV UUID O0VAmw-8M5T-Ek2g-AtMO-jDeR-xvPm-OQusKE

    --- Physical Segments ---
    Physical extent 0 to 1780:
    FREE

    --- Physical volume ---
    PV Name /dev/sda4
    VG Name FourT
    PV Size 108.03 GB / not usable 32.06 MB
    Allocatable yes
    PE Size (KByte) 32768
    Total PE 3456
    Free PE 1675
    Allocated PE 1781
    PV UUID Os3abz-5zRI-LRfN-iaUF-ZaAr-gVUY-okAF3L

    --- Physical Segments ---
    Physical extent 0 to 319:
    Logical volume /dev/FourT/fsroot
    Logical extents 0 to 319
    Physical extent 320 to 1119:
    Logical volume /dev/FourT/Private
    Logical extents 0 to 799
    Physical extent 1120 to 1279:
    Logical volume /dev/FourT/home
    Logical extents 0 to 159
    Physical extent 1280 to 1748:
    Logical volume /dev/FourT/Others
    Logical extents 0 to 468
    Physical extent 1749 to 1780:
    Logical volume /dev/FourT/swap
    Logical extents 0 to 31
    Physical extent 1781 to 3455:
    FREE
    可知旧硬盘上数据已经全部迁移了。切记,如果pvmove被中断,请使用pvmove命令继续上次移动,不需要其他参数。
  7. 将物理卷/dev/sda2从卷组FourT中移除:vgreduce FourT /dev/sdb2
  8. 使用vgdisplay检查卷组容量,确认/dev/sda2已经不在卷组中: --- Volume group ---
    VG Name FourT
    System ID
    Format lvm2
    Metadata Areas 1
    Metadata Sequence No 19
    VG Access read/write
    VG Status resizable
    MAX LV 0
    Cur LV 5
    Open LV 5
    Max PV 0
    Cur PV 1
    Act PV 1
    VG Size 108.00 GB
    PE Size 32.00 MB
    Total PE 3456
    Alloc PE / Size 1781 / 55.66 GB
    Free PE / Size 1675 / 52.34 GB
    VG UUID LznCQc-SLKV-tejY-SSUS-PsrB-NA8S-ssOfT4
  9. 使用df确认旧硬盘已经未使用,确认后移除USB移动硬盘(要的就是心跳,结果系统依然在跑,瓦哈哈哈哈)。
重启前最后的检查:
  1. 运行grub,然后使用下列命令,将MBR写如新的硬盘:root (hd0,2)
    setup (hd0)
  2. 检查/etc/fstab中UUID部分是否为新硬盘的分区UUID。
  3. 检查GRUB中的UUID是否正确。
  4. 运行mkinitramfs或者其他类似命令,确保新硬盘驱动已经包含在initfs中(大部分系统不需要此步骤)。
本文参考:
IBM Developerworks Common threads: Learning Linux LVM, Part 1
IBM Developerworks Common threads: Learning Linux LVM, Part 2

Friday, February 27, 2009

Proftpd user authentication using Mysql

Preparation:
  1. Mysql and Mysql-devel (No need if you were using the self-compiling mysql).
  2. Proftpd source package.
  3. Develop environment.
Compilation:
  1. Compile mysql or install mysql-devel. I just compile and install it into /opt/mysql
  2. Compile proftpd using the following code:
    ./configure --with-modules=mod_sql:mod_sql_mysql \
    --prefix=/opt/proftpd \
    --with-includes=/opt/mysql/include/mysql \
    --with-libraries=/opt/mysql/lib

  3. Create database for proftpd, using the following SQL command:
    CREATE DATABASE proftpd;
  4. Create a database user for proftpd, using the following SQL command:
    GRANT select,insert,update,delete,create,drop,index,alter,create temporary tables,lock tables on proftpd.* to proftpd@localhost Identified by "123456";
  5. Create database tables for proftpd, using the following SQL command:
    CREATE TABLE `proftpd`.`ftpgroups` (
    `groupname` varchar(30) NOT NULL,
    `gid` int(10) NOT NULL ,
    `members` varchar(255) NOT NULL
    )
    ENGINE = MyISAM DEFAULT CHARSET=latin1;

    CREATE TABLE `proftpd`.`ftpusers` (
    `username` VARCHAR(30) NOT NULL,
    `passwd` varchar(80) NOT NULL,
    `uid` int(10) NOT NULL DEFAULT,
    `gid` int(10) NOT NULL DEFAULT,
    `homedir` varchar(255) NOT NULL,
    `shell` varchar(255) NOT NULL,
    `count` int(10) NOT NULL DEFAULT '0',
    `host` varchar(30) NOT NULL,
    `lastlogin` varchar(30) NOT NULL,
    UNIQUE KEY `username` (`username`)
    )
    ENGINE = MyISAM DEFAULT CHARSET=latin1;

  6. Change the configuration file ( /opt/proftpd/etc/proftpd.conf ) of proftpd:
    AllowStoreRestart on
    RequireValidShell off
    AllowOverwrite on
    DefaultRoot ~

    SQLConnectInfo proftpd@localhost proftpd 123456
    SQLNegativeCache on
    SQLAuthTypes Plaintext
    SQLAuthenticate users groups
    SQLUserInfo ftpusers username passwd uid gid homedir shell
    SQLGroupInfo ftpgroups groupname gid members
    SQLNamedQuery getcount SELECT "count from ftpusers where username='%u'"
    SQLNamedQuery getlastlogin SELECT "lastlogin from ftpusers where username='%u'"
    SQLNamedQuery updatelogininfo UPDATE ftpusers "count=count+1,host='%h',lastlogin=current_timestamp() WHERE username='%u'"
    #SQLShowInfo PASS "230" "You've logged on %{getcount} times, last login at %{getlastlogin}"

  7. INSERT the user info into the database, using the following SQL command:
    INSERT INTO `ftpusers` VALUES ('test1', 'test1', 2000, 2000, '/opt/ftp/test1', '/sbin/nologin',0,'','');
  8. There is no need to INSERT group info into the database.
I have write a Perl script to manage the user info in database. click to view and download.

Saturday, January 03, 2009

3 Jan 2009

玩了近一个下午,惟一有意义的事是把KDE4删除了,回归KDE3。压抑以久的愤怒终于爆发了。顺便把BUG巨多的opensuse版的openoffice.org3删除了。SCIM与OOo的兼容问题就不说了。还是MS office方便。凯撒的归凯撒,微软的归微软,还好我不是文员。
晚上看柯南然后看IGMP v2的RFC文档。专心看RFC文档的话,效率还是很高的。就差host间通讯以及IGMP v2对IGMP v1的兼容这两个部分就搞定了。
多播文档余下任务:
1。IGMP v3
2。CGMP 和 IGMP snooping
3。Hoot ‘n’ Holler
4。各个厂商配置方法。
5。Perl写个多播小程序。

早知道,要学多播,就直接申请成毕设了。毕设内容:访问控制 还没什么头绪。

Friday, January 02, 2009

使用Perl的Spreadsheet::WriteExcel模块生成包含中文的excel

原以为Perl 5.8以后对UTF8处理很完美,结果2个小时的郁闷是缺如下无用命令:
decode( 'utf8', $utf_8_strings );
看似无用的一行,居然在 Spreadsheet::WriteExcel 中是必须的,请求高人指点缘由。

如果脚本是按照UTF -8编码保存的,那么生成中文excel的脚本如下:
use Encode;
use Spreadsheet::WriteExcel;
my $workbook = Spreadsheet::WriteExcel->new("$output_file");
my $worksheet_device_status =
$workbook->add_worksheet( decode( 'utf8', "设备运行状态" ) );
$worksheet_device_status->merge_range(
'A1:J1',
decode('utf8',
"信息技术中心网络设备代维巡检日报-设备运行情况"
),
$format_title_merge_1
);
$worksheet_device_status->write( 'E4', decode( 'utf8', "5分钟" ),
$format_title_1 );

如果脚本是GBK编码(windows上写的脚本),那么应该将
decode( 'utf8', $strings )换成decode( 'GB2312', string )。

Thursday, January 01, 2009

Perl 的use strict总结

昨天写了一天脚本。忘写blog了。今天补上。

帮朋友写一个报告自动生成的脚本。习惯性的用上use strict。结果strict sub和strict vars把我折腾了很久。
总结如下:
1。全局变量声明:
use vars qw($log_dir $output_file @cpu_mem_results_ref $results_id $device_id);
语法是use vars @array 故最好用qw将所有全局变量列表转化成数组。
2。subroutine 中处理文件(处理文件夹没有限制):
sub check_device {
my $file_handle;
open $file_handle, "<", "$_[0]/$_[1]" or die "cannot open $_[0]/$_[1]:$!";
foreach (<$file_handle>){print $_;};
close $file_handle;
}

不能使用直接的FH这样的filehandler了。
看来写Perl散漫惯了不行阿。

新年快乐。

Monday, December 29, 2008

29 Dec 2008

EMC的纸质offer终于到了。HR还是蛮细心的(虽然忘了寄接收函),居然有德芙做为圣诞礼物。
给恒生写了很正式的解约邮件,罗工很了解我,说做朋友也不错。故,继续帮罗工写Multicast的文档。
看RFC是很痛苦的,但收获也不少。
最后依然是摘抄
KJV
Romans 8:38 - 8:39
38 For I am persuaded, that neither death, nor life, nor angels, nor principalities, nor powers, nor things present, nor things to come,
39 Nor height, nor depth, nor any other creature, shall be able to separate us from the love of God, which is in Christ Jesus our Lord.