Friday, October 28, 2011

how to make thunderbird notify new email like evolution on ubuntu

หลังจาก install thunderbird แล้ว ก็เกิดอยากได้ notify new email แบบ evolution บ้างจึงลองค้นดูก็เจอคนถามใน askubuntu พอดีเลย วิธีการคือ
  • add repository and update
    sudo add-apt-repository ppa:ruben-verweij/thunderbird-indicator
    sudo apt-get update
  • Install package
    sudo apt-get install xul-ext-indicator libnotify-bin
จากนั้นสังเกตุไอคอน indicator จะพบ ไอคอน thunderbird อยู่ และเมื่อมี new email ก็จะมี notify แล้วครับ

Read More

Thursday, October 27, 2011

how to install thunderbird

หลัง ๆ เริ่มได้ใช้โปรแกรมดูดเมล์มา เริ่มตั้งแต่ outlook on windows , evolution mail on ubuntu ก็พอใช้งานได้ แต่สำหรับ evolution เริ่มใช้งานมากขึ้นเจอกับเมล์ข้อความหลาย ๆ บรรทัด ( 2000 - 3000 บรรทัด ) ทีไรเลื่อน ๆ ดูข้อความแล้วชอบเด้งออกตลอดเลย แต่ก็ไม่ค่อยได้ไปสนใจเท่าไร พอดีวันนี้เจอเว็บ webupd8 พูดถึง thunderbird จึงลองดูบ้าง โดยขั้นตอนการ install จาก webupd8 สำหรับ Ubuntu 11.04, 10.10 or 10.04
  1. add repository and update package
    sudo add-apt-repository ppa:mozillateam/thunderbird-stable
    sudo apt-get update
  2. Install thunderbird
    sudo apt-get install thunderbird
  3. Install calendar plugin
    sudo apt-get install xul-ext-lightning
  4. ถ้าหากต้องการปรับแต่งหน้าตาให้ดูดีขึ้น ก็ลง add-on เพิ่มเข้าไป โดยไปโหลด Thunderbird Conversations เก็บไว้ในเครื่องแล้วเข้าโปรแกรม thunderbird แล้วเลือกที่ Tools -> Add-ons แล้วคลิกที่ไอคอน Tools for all add-ons แล้วเลือก Install Add-on from file จากนั้นก็ restart thunderbird ก็จะได้ตามรูป
  5. ถ้าหากมี calendar from evolution ให้ open thunderbird calendar, go Events&Task->import, and look into .local/share/evolution/calendar/system/calendar.ics file...
    หรือถ้ามีข้อมูลเกี่ยวกับ filter หรือการตั้งค่าต่าง ๆ สามารถใช้ tools->import เลยได้ แต่สำหรับผมเหมือนมันจะยังไม่โอเคนะ

Read More

Tuesday, October 25, 2011

how to move multiple file with CLI

การย้ายไฟล์จากที่หนึ่งไปยังอีกที่หนึ่ง ปกติแล้วถ้าหากใช้ Windows ก็จะเลือกไฟล์หลาย ๆ ไฟล์จากนั้นก็ Drag & Drop file ไปไว้อีกทีนึงได้เลย แต่ถ้าเป็น CLI (Command Line Interface) ละจะทำอย่างไร?
หากต้องการ move file ทั้ง directory '/home/user/a' and rename directory to directory '/home/user/b' เลยอาจใช้คำสั่งนี้
mv /home/user/a /home/user/b
หาก /home/user/b exist can use this command
mv /home/user/a/* /home/user/b
ในขณะที่ file ที่ต้องการจะ move มีบางไฟล์จาก /home/user/a โดยที่ต้องการ move file ที่ไม่ได้ถูกเปลี่ยนแปลงมาแล้วเกินกว่า 30 วัน
find /home/user/a -type f -mtime +30 -exec mv '{}' /home/user/b \;

Read More

Wednesday, October 19, 2011

automatic shutdown server by cron

หลาย ๆ ครั้งที่เครื่อง Server ไม่สามารถ shutdown ได้ในเวลาที่เราทำงาน ครั้นจะให้กลับมา shutdown ตอนดึก ๆ ก็คงจะไม่ดี ตัวช่วยในเรื่องเวลาที่ ubuntu, debian, linux, bsd, freebsd, unix ต่างก็มีนั่นก็คือ cron
การใช้งาน
เข้า Terminal แล้วใช้คำสั่ง สำหรับการตั้งเวลา cron ด้วย root
sudo crontab -e
หากว่าไม่ต้องการใช้ root ตั้งเวลา cron ต้องการเพียงแค่ user ที่ login อยู่ให้ใช้คำสั่ง
crontab -e
หากเรียกใช้งาน crontab ครั้งแรกอาจมีคำถามว่าต้องการเลือก shell editor แบบไหน ผมขอแนะนำให้เลือก nano สำหรับมือใหม่ครับ
เมื่อเรียกใช้คำสั่งแล้วจะพบกับหน้าจอสำหรับ กำหนดให้ cron ทำงาน โดย cron จะมีฟอแมตคือ
MIN HOUR DOM MON DOW CMD
โดยที่
MIN คือนาที มีค่าตั้งแต่ 0 - 59
HOUR คือชั่วโมง มีค่าตั้งแต่ 0 - 23
DOM ย่อมาจาก Day of month คือวันที่นั่นเองครับ มีค่าตั้งแต่ 1 - 31 ตามจำนวนวันในเดือนนั้น ๆ
MON คือเดือน มีค่าตั้งแต่ 1 - 12
DOW ย่อมาจาก Day of week คือ วันในสัปดาห์ มีค่าตั้งแต่ 0 - 6 โดยที่เริ่มตั้งแต่ 0 คือวันอาทิตย์, 1 คือวันจันทร์ ... ไล่ไปเรื่อย ๆ จน 6 คือวันเสาร์
CMD คือคำสั่งที่ต้องการจะสั่งให้ server ทำงานอัตโนมัติตามเวลาที่กำหนด ซึ่งตามบทความนี้คำสั่งที่จะใช้คือ shutdown -h now สำหรับปิดเครื่อง และ reboot สำหรับ restart เครื่อง server
เมื่อรู้ความหมายของ format cron แล้วดังนั้น หากต้องการปิดเครื่อง server ทุกวันเวลา ตีสาม คำสั่งคือ
00 03 * * * /sbin/shutdown -h now
ตัวอย่างสำหรับหากต้องการ restart server ในวันที่ 20 ตุลาคม เวลา ตีสาม ห้านาที มีคำสั่งคือ
05 03 20 10 * /sbin/reboot
เมื่อทำการแก้ไขเสร็จแล้วให้ save ด้วยคีย์ Ctrl+o กด enter และออกจาก editor ด้วยคีย์ Ctrl+x (สำหรับ editor nano) เพียงเท่านี้เครื่อง server ก็สามารถทำงานได้ตามที่เราต้องการโดยไม่ต้องนั่งหน้าเครื่องแล้วครับ

Read More

Cache .dep with squid-deb-proxy server

ปกติถ้าหากใช้เครื่องที่มี ubuntu เพียงเครื่องเดียวก็จะไม่มีความจำเป็นที่จะต้องเก็บ .dep ไว้ในเครื่อง server แต่ถ้าหากมีคนใช้ ubuntu ในออฟฟิศเดียวกันหลาย ๆ คน ครั้นจะให้แต่ละคนอัพเดตของตัวเองก็เกรงจะเปลือง bandwidth โดยใช่เหตุ ดังนั้นตัวช่วยในบทความนี้คือ squid-deb-proxy โดยมีขั้นตอนการติดตั้ง
[server]
  1. Install packages
    sudo apt-get install avahi-utils
    sudo apt-get install squid-deb-proxy
  2. Edit Configuration
    sudo vi /etc/squid-deb-proxy/allowed-networks-src.acl
    Add LAN IP such as LAN IP is 192.168.1.0 - 192.168.1.255 :
    192.168.1.0/24

    sudo vi /etc/squid-deb-proxy/mirror-dstdomain.acl
    Add all repository from all client ( can see in file /etc/apt/source.list ) to configuration file :
    # default ubuntu and ubuntu country archive mirrors
    .archive.ubuntu.com
    ports.ubuntu.com
    security.ubuntu.com
    #official third party repositories
    archive.canonical.com
    extras.ubuntu.com


  3. Restart service :
    sudo service avahi-daemon restart
    sudo service squid-deb-proxy start
    
  4. Check log file at :
    sudo tail -f /var/log/squid-deb-proxy/access.log

[Client]
  1. Install squid-deb-proxy-client
    sudo apt-get install squid-deb-proxy-client
  2. Check client con connect to proxy

    avahi-browse -kprt _apt_proxy._tcp
    +;eth2;IPv4;Squid\032deb\032proxy;_apt_proxy._tcp;local
    =;eth2;IPv4;Squid\032deb\032proxy;_apt_proxy._tcp;local;squidserver.local;192.168.1.10;8000;

    192.168.1.10 is squid-proxy-server
และหากต้องการยกเลิกการใช้งาน proxy ชั่วคราว สามารถทำการแก้ไขไฟล์ 30autoproxy ได้
sudo vi /etc/apt/apt.conf.d/30autoproxy
จากนั้นใส่เครื่องหมาย # ด้านหน้าบรรทัดแบบนี้
#Acquire::http { Proxy "http://192.168.1.10:8000/"; };

Read More

Tuesday, October 18, 2011

how to install openvpn + heartbeat on ubuntu server

การเชื่อมต่อข้อมูลสำหรับองค์กร ในบางครั้งจะมีข้อมูลที่ไม่อยากเอาขึ้น internet อาจเป็นข้อมูลที่มีความลับจึงไม่อยากเสี่ยงที่จะเอาขึ้น internet ดังนั้นจึงทำเป็น intranet (สำหรับในเครือข่าย lan เดียวกัน) ขึ้น แต่เมื่อมี สาขา เพิ่มขึ้นความต้องการใช้ข้อมูลของสาขาแรกในสาขาใหม่ที่อยู่ห่างออกไปก็มี แนวทางในการแก้ปัญหาแนวทางหนึ่งก็คือ openvpn เป็นการเชื่อมโยงสาขาใหม่ให้เสมือนทำงานอยู่ที่เดียวกับสาขาแรก โดยในบทความนี้จะแสดงขั้นตอนการ install openvpn step by step พร้อมกับ install heartbeat เพื่อคอยตรวจสอบ openvpn server โดยมี openvpn server จำนวน 2 เครื่อง ดังรูปด้านบน
กำหนดให้ openvpn server 2 เครื่องคือ 192.168.2.21 ( primary ) and 192.168.2.22 ( slave )
กำหนด virtual ip 192.168.2.20 openvpn
กำหนด real ip 123.4.5.6 ( เป็น firewall ที่ทำการ forward port ไปที่ openvpn server )

[Server]
  1. Install openvpn
    sudo apt-get install openvpn
  2. Copy files from /usr/share/doc/openvpn/examples/easy-rsa to /etc/openvpn
    sudo mkdir /etc/openvpn/easy-rsa
    sudo cp -R /usr/share/doc/openvpn/examples/easy-rsa/2.0/* /etc/openvpn/easy-rsa/
  3. Edit file vars
    sudo vi /etc/openvpn/easy-rsa/vars
    Change these lines
    export KEY_COUNTRY="TH" #Change to your Country
    export KEY_PROVINCE="CM" #Change to your Province
    export KEY_CITY=""
    export KEY_ORG=""
    export KEY_EMAIL=""
  4. Setup CA and create server certificate
    cd /etc/openvpn/easy-rsa/
    sudo chown -R root:admin .
    sudo chmod g+w .
    source ./vars
    ./clean-all
    ./build-dh
    ./pkitool --initca
    ./pkitool --server server
    cd keys
    openvpn --genkey --secret ta.key
    sudo cp server.crt server.key ca.crt dh1024.pem ta.key ../../
  5. Create certificate file for client
    cd /etc/openvpn/easy-rsa
    source ./vars
    ./pkitool
    note : change to user machine.
  6. Configuring openvpn
    sudo vi /etc/openvpn/server.conf
    Change config :
    local 192.168.2.20   #virtual ip for heartbeat
    port 1194 
    # TCP or UDP server? 
    proto tcp 
    dev tun 
    ca /etc/openvpn/ca.crt 
    cert /etc/openvpn/server.crt 
    key /etc/openvpn/server.key  # This file should be kept secret 
    
    dh /etc/openvpn/dh1024.pem 
    server 192.168.201.0 255.255.255.0   #virtual ip for tunnel
    ifconfig-pool-persist ipp.txt 
    push "dhcp-option DOMAIN simdif.local" 
    push "dhcp-option DNS 192.168.2.1"           #DNS
    push "route 192.168.2.0 255.255.255.0" 
    push "route 192.168.201.0 255.255.255.0" 
    client-to-client 
    tls-auth ta.key 0 # This file is secret 
    comp-lzo 
    user nobody 
    group nogroup 
    persist-key 
    persist-tun 
    status openvpn-status.log 
    verb 4
    
  7. Restart service openvpn
    sudo /etc/init.d/openvpn restart
  8. ทำขั้นตอน 1-7 อีกครั้งกับเครื่อง openvpn server อีกเครื่อง
  9. Install heartbeat
    sudo apt-get install heartbeat
  10. Copy original config to /etc/ha.d/
    cd /usr/share/doc/heartbeat
    sudo cp ha.cf haresources authkeys /etc/ha.d/
  11. Edit ha.cf
    sudo vi /etc/ha.d/ha.cf
    Check and edit configuration
    debugfile /var/log/ha-debug 
    logfacility     local0 
    keepalive 4 
    deadtime 60 
    warntime 10 
    initdead 120 
    udpport 694 
    bcast   eth0            # Linux 
    auto_failback on 
    node openvpnserver01 
    node openvpnserver02
    ping_group group1 192.168.2.21 192.168.2.22
    
  12. Edit haresources
    sudo vi /etc/ha.d/haresources
    Change to :
    openvpnserver01 192.168.2.20 openvpn
  13. Edit authkeys
    sudo vi /etc/ha.d/authkeys
    Change to :
    auth 2
    2 sha1 test-ha
  14. Copy configuration file to 192.168.2.22
    cd /etc/ha.d
    scp ha.cf haresources authkeys username@192.168.2.22:
  15. Go to 192.168.2.22 and copy file to /etc/ha.d
    cd ~
    sudo cp ha.cf haresources authkeys /etc/ha.d
  16. Start heartbeat on the primary 192.168.2.21 and slave 192.168.2.22
    sudo /etc/init.d/heartbeat start
  17. Create firewall NAT both vpn server
    sudo echo 1 > /proc/sys/net/ipv4/ip_forward
    sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  18. Edit file /etc/rc.local
    sudo vi /etc/rc.local
    Add 2 lines to configuration file
    sudo echo 1 > /proc/sys/net/ipv4/ip_forward
    sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    exit 0
    

[Client]
  1. Install openvpn
    sudo apt-get install openvpn
  2. Copy certificate file from server ca.crt .crt .key ta.key to /etc/openvpn
  3. Edit configuration
    sudo vi /etc/openvpn/client.conf
    Change to :
    client 
    dev tun 
    proto tcp 
    remote 123.4.5.6 1194 
    resolv-retry infinite 
    nobind 
    user nobody 
    group nogroup 
    persist-key 
    persist-tun 
    ca ca.crt 
    cert .crt 
    key .key 
    tls-auth ta.key 1 
    comp-lzo 
    verb 3
    log-append /var/log/openvpn.log
    
  4. Restart service openvpn
    sudo /etc/init.d/openvpn restart
  5. Check connection
    ifconfig
    tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
              inet addr:192.168.201.6  P-t-P:192.168.201.5  Mask:255.255.255.255 
              UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1 
              RX packets:152 errors:0 dropped:0 overruns:0 frame:0 
              TX packets:182 errors:0 dropped:0 overruns:0 carrier:0 
              collisions:0 txqueuelen:100 
              RX bytes:51111 (51.1 KB)  TX bytes:21776 (21.7 KB)
    

Read More

Monday, October 17, 2011

How to find current runlevel on unix with who

คำสั่ง who เป็นคำสั่งเอาไว้แสดงว่าตอนนี้มีใคร log in อยู่ในระบบบ้าง โดยเมื่อใช้คำสั่ง
who
จะแสดงผลประมาณนี้
yut  tty7         2011-10-17 08:55 (:0)
yut  pts/1        2011-10-17 08:55 (:0)
ในขณะที่คำสั่งสำหรับดู previous and current runlevel ก็คือคำสั่ง runlevel
runlevel
N 2
แต่สำหรับคำสั่ง who นั้นสามารถดู current runlevel ได้ด้วยคำสั่ง
who -r
         run-level 2  2011-10-17 08:54
โดยถ้าหากต้องการดูทั้ง current runlevel และ ดูว่ามีใคร log in ในระบบด้วย จะใช้คำสั่ง
who -a
           system boot  2011-10-17 08:54
           run-level 2  2011-10-17 08:54
LOGIN      tty4         2011-10-17 08:54              1008 id=4
LOGIN      tty5         2011-10-17 08:54              1014 id=5
LOGIN      tty2         2011-10-17 08:54              1034 id=2
LOGIN      tty3         2011-10-17 08:54              1036 id=3
LOGIN      tty6         2011-10-17 08:54              1042 id=6
LOGIN      tty1         2011-10-17 08:54              1637 id=1
yut        + tty7         2011-10-17 08:55  old         2043 (:0)
yut       + pts/1        2011-10-17 08:55 01:03        2133 (:0)

ที่มา www.theunixtips.com

Read More