Monday, December 15, 2014

Ubuntu server 14.04 - Auto mount network Drive Issue

Recently, due to maintanance upgrade I have to reboot my Server and notice that it stuck at boot screen waiting for external Network drive to mount. Previous article ubuntu-server-auto-mount-iscsi-storage

The message is "the disk drive for /backupdata is not ready or not presented". 2 things I can do:

Remount network drive with UUID instead of /dev/blah..blah in /etc/fstab
#> blkid
/dev/mapper/datavg-backupdata: UUID="85e81bbc-2c86-4bef-b1e9-f77d21929de5" TYPE="xfs" 

Add nobootwait option into mount target in /etc/fstab
UUID=85e81bbc-2c86-4bef-b1e9-f77d21929de5 /backupdata xfs auto,rw,user,nobootwait 0 0

Then reboot my system and It work!

Thursday, December 11, 2014

Backuppc add administrator account

Adding a CGI Administrator

as root privilege open up /etc/backuppc/config.pl and go to line 2020
$Conf{CgiAdminUserGroup} = 'backuppc';
$Conf{CgiAdminUsers} = 'backuppc, admin';

Reload Backuppc service
service backuppc reload

Adding Administrator to htpasswd for Apache basic authentication

htpasswd /etc/backuppc/htpasswd admin

Restart Apache service
service apache2 restart

http://wiki.zmanda.com/index.php/BackupPC_Web_Interface

Tuesday, December 9, 2014

Ubuntu server auto mount iSCSi storage

Install Open-iSCSI initiator
apt-get install open-iscsi

configuration file could be located at /etc/iscsi/iscsid.conf or ~/.iscsid.conf.
node.startup = automatic
node.session.auth.username = MY-ISCSI-USER
node.session.auth.password = MY-ISCSI-PASSWORD
discovery.sendtargets.auth.username = MY-ISCSI-USER
discovery.sendtargets.auth.password = MY-ISCSI-PASSWORD

Discover iSCSi Target
iscsiadm -m discovery -t sendtargets -p 172.31.1.150

Login to target
iscsiadm --mode node --targetname iqn.1992-04.com.emc:cx.fcnma082600013.a0 --portal 172.31.1.150 --login

Note: remember login to your iSCSi server (SAN) then allow your server connection
Make sure you auto connect to iSCSi server target when server start up
vi /etc/iscsi/nodes/iqn.1992-04.com.emc\:cx.fcnma082600013.b1/172.31.2.151\,3260\,3/default

node.startup = automatic

Restart service
/etc/init.d/open-iscsi restart

Format and mount the iSCSi volume

dmesg or fdisk -l, or look at /var/log/messages to find new devices
You can use LVM or partition your disk now
fdisk /dev/sde

Format a partition ext4 or xfs or brtfs
mkfs.ext4 /dev/sde1

Mount file system
mkdir /backupdata
mount /dev/sde1 /backupdata

Add mount point to /etc/fstab 
/dev/sde1  /backupdata ext4 defaults 0 0

Monday, December 8, 2014

Bonding Network Card Ubuntu 14.04

Make sure your Cisco Switch support 802.3ad, then group 2 interface ports together
Router> enable
Router# configure terminal
Router(config)# interface port-channel 1
Router(config-if)# interface g1/0/24
Router(config-if)# channel-group 1 mode active
Router(config-if)# exit
Router(config)# interface g1/0/23
Router(config-if)# channel-group 1 mode active
Router(config-if)# end
Router# copy run start

Bonding mode: http://www.mjmwired.net/kernel/Documentation/networking/bonding.txt#508
802.3ad or 4 : IEEE 802.3ad Dynamic link aggregation. Creates aggregation groups that share the same speed and duplex settings. Utilizes all slaves in the active aggregator according to the 802.3ad specification.

Bonding network card on Ubuntu Server
apt-get install ifenslave-2.6
echo "bonding" >> /etc/modules
modprobe bonding

vi /etc/network/interface
auto em1
iface em1 inet manual
bond-master bond0
bond-primary em1

auto em2
iface em2 inet manual
bond-master bond0

auto bond0
iface bond0 inet static
bond-slaves none
bond-mode 4
bond-miimon 100
        address 192.168.1.111
        netmask 255.255.0.0
        network 192.168.0.0
        broadcast 192.168.255.255
        gateway 192.168.1.1
        dns-nameservers 192.168.1.1 

Reboot server and wait a little bit for the bond interface become active

http://www.paulmellors.net/ubuntu-server-14-04-lts-nic-bonding/
http://ilostmynotes.blogspot.com/2009/04/bridging-bonded-network-interface-on.html

Thursday, December 4, 2014

Ubuntu - 3 tricks to copy DVD into iso file

Built in command

cat /dev/sr0 > /home/Documents/mydisk.iso
dd if=/dev/sr0 of=/home/Documents/mydisk.iso

If both cat, and dd not work because of '/dev/sr0': Input/output error
If I run dmesg, I recieve a lot of Buffer I/O error on device sr0

Try ddrescue in Ubuntu the package is gddrescue
sudo apt-get install gddrescue
ddrescue --direct --block-size=2048 --no-split /dev/sr0 /home/Documents/mydisk.iso

Now you can open iso file with VLC

Tuesday, December 2, 2014

Linux find command for files or folders older than .....

Find files and folders in current working directory older than 60 days
find ./* -maxdepth 0 -mtime +60

Find only folders in /mnt/media -> child folder -> grandchild exclude these folder notme, dtran, xXXx older than 3 years
find /mnt/media -maxdepth 2 -mtime +1095 -type d -not \( -path "./notme*" -o -path "./dtran*" -o -path "./xXXx*" \) > ~/Folder2Backup.txt

Remove all files that have xxx in names and older than 2 years
find ./ -type f -name "*xxx*.*" -mtime +730 -exec rm "{}" \;

Windows not a big deal, install Cygwin and Finding Nemoooo
find /cygdrive/f -maxdepth 2 -type d -mtime +730 > ~/dir_older_than_2years.txt

Find directory older than 2 years and list its size
find /cygdrive/f -maxdepth 1 -type d -mtime +730 -exec du -sh "{}" \; 

Apple flush DNS cache

Open Terminal and run this command

dscacheutil -flushcache

TTL and DNS cache

Time to Live (TTL) is used to renew the DNS records on all the DNS servers around the world to the set TTL value. 

The units used are seconds. The older common TTL value for DNS was 86400 seconds, which is 24 hours. A TTL value of 86400 would mean that, if a DNS record was changed on the authoritative name server, the DNS servers around the world could still be showing the old value from their cache for up to 24 hours after the change.

Why change the TTL value

If you want to make quick DNS changes, it is a good practice to place a low TTL value. The TTL values can be changed by logging in to the the Self Service Center.
If you change the TTL, you have to wait for the current TTL to pass before the new TTL will be active. This means that if you change the TTL to 1 hour instead of 24 hours, you have to wait the 24 hours first before the 1 hour TTL wil be active.

Setting a TTL value lower than 12 hours is not recommended, and should only be used during a short period for special cases. By default, the TTL value is 24 hours.

Friday, November 28, 2014

Listing directory in Graphical format in Bash

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'

Script from centerkey.com: http://www.centerkey.com/tree/tree.sh
#!/bin/sh
#######################################################
#  UNIX TREE                                          #
#  Version: 2.3                                       #
#  File: ~/apps/tree/tree.sh                          #
#                                                     #
#  Displays Structure of Directory Hierarchy          #
#  -------------------------------------------------  #
#  This tiny script uses "ls", "grep", and "sed"      #
#  in a single command to show the nesting of         #
#  sub-directories.  The setup command for PATH       #
#  works with the Bash shell (the Mac OS X default).  #
#                                                     #
#  Setup:                                             #
#     $ cd ~/apps/tree                                #
#     $ chmod u+x tree.sh                             #
#     $ ln -s ~/apps/tree/tree.sh ~/bin/tree          #
#     $ echo "PATH=~/bin:\${PATH}" >> ~/.profile      #
#                                                     #
#  Usage:                                             #
#     $ tree [directory]                              #
#                                                     #
#  Examples:                                          #
#     $ tree                                          #
#     $ tree /etc/opt                                 #
#     $ tree ..                                       #
#                                                     #
#  Public Domain Software -- Free to Use as You Like  #
#  http://www.centerkey.com/tree  -  By Dem Pilafian  #
#######################################################
echo
if [ "$1" != "" ]  #if parameter exists, use as base folder
   then cd "$1"
   fi
pwd
ls -R | grep ":$" |   \
   sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'
# 1st sed: remove colons
# 2nd sed: replace higher level folder names with dashes
# 3rd sed: indent graph three spaces
# 4th sed: replace first dash with a vertical bar
if [ `ls -F -1 | grep "/" | wc -l` = 0 ]   # check if no folders
   then echo "   -> no sub-directories"
   fi
echo
exit

Add it to your system. Please watch out the code before running it!
curl http://www.centerkey.com/tree/tree.sh > /usr/bin/tree
chmod +x /usr/bin/tree
 
 http://stackoverflow.com/questions/3455625/linux-command-to-print-directory-structure-in-the-form-of-a-tree

Compare 2 directory in Linux

Let's make an example. Create 2 folder and put files in it
mkdir dir{1,2}
touch dir1/{1,2,3,4,5,6}.txt
touch dir2/{2,4,5,7,9}.txt

ls -R dir1
dir1:
1.txt  2.txt  3.txt  4.txt  5.txt  6.txt

ls -R dir2
dir2:
2.txt  4.txt  5.txt  7.txt  9.txt

diff -r dir1 dir2
Only in dir1: 1.txt
Only in dir1: 3.txt
Only in dir1: 6.txt
Only in dir2: 7.txt
Only in dir2: 9.txt

http://stackoverflow.com/questions/16787916/difference-between-2-directories-in-linux

Ubuntu Change Date from IST to ICT

If you try to change your clock, NTP setting and sync to hardware clock but the date still wrong so here's how
#date
Thu Nov 27 08:16:23 IST 2014  #wrong date time
#dpkg-reconfigure tzdata
Current default time zone: 'Asia/Ho_Chi_Minh'
Local time is now: Thu Nov 27 09:48:02 ICT 2014.
Universal Time is now: Thu Nov 27 02:48:02 UTC 2014.

#date
Thu Nov 27 09:48:09 ICT 2014  #correct now

Thursday, November 20, 2014

Âm nhạc chữa lành bệnh tật

Trong các ca phẫu thuật, âm nhạc giúp giảm thiểu cảm giác đau đớn. Nó cũng khiến bệnh nhân bớt lo âu sợ hãi trước và sau mổ, đẩy nhanh sự hồi phục sức khỏe của bệnh nhân.

Vài nghiên cứu mới đây tìm ra sự liên hệ giữa tần số của vài điệu nhạc với điện năng của tế bào não. Nếu dùng một tần số nhạc nào đó, ta có thể tăng khả năng học hỏi, thư giãn cơ thể, giúp ngủ ngon giấc. Do đó, theo nhiều nhạc sĩ, để hưởng ích lợi của nhạc điệu, bạn không những chỉ nghe mà còn phải để toàn thân rung động theo điệu nhạc.

Fabien Maman, soạn nhạc gia kiêm sinh học gia người Pháp, đã quan sát ảnh hưởng của âm thanh lên tế bào ung thư. Dưới tác dụng của các âm điệu khác nhau từ nhạc khí hoặc lời ca, tế bào bệnh dường như không chịu đựng được sự dao động và vỡ tung, nhất là với tiếng hát cao vút.

Âm nhạc trị liệu
Các nghiên cứu xưa nay đều cho thấy, âm nhạc trước hết làm cho con người được phát triển toàn diện ngay từ trong bụng mẹ. Thai nhi được cho “nghe nhạc” thường khỏe hơn các thai nhi khác. Các bác sĩ vẫn khuyên thai phụ nên nghe nhạc êm dịu và cho thai nhi cùng nghe. Em bé được nghe mẹ hát ru từ thuở còn thơ thường thông minh và khi lớn lên ít bị những bệnh về tâm trí.

Nhạc còn giúp thư giãn, giảm thiểu lo âu, đau đớn, giảm cô lập với xã hội, tăng sự tập trung, chú ý, kích thích cảm xúc và nhận thức. Nhạc cũng giúp cơ thể có nhiều sinh lực, kích động não bộ, làm thức tỉnh các cảm xúc, tháo gỡ các xúc động, phục hồi tâm hồn, làm hứng khởi hành động, giúp ngủ ngon, giúp lý luận tốt cũng như giúp tránh lao tâm suy nghĩ.

Nhạc trị liệu không chỉ là nghe nhạc mà còn là tham dự các sinh hoạt liên quan tới âm nhạc. Mọi người đều có thể tận hưởng các lợi điểm của nhạc miễn là để toàn thân rung động, hòa nhịp theo tiếng hát lời ca.

Ngày nay, nhạc trị liệu là lĩnh vực trong đó âm nhạc được sử dụng như một phương thức phục hồi, duy trì và hoàn thiện đời sống của người bệnh về thể chất, tinh thần và cảm xúc. Nhạc được coi như một nghệ thuật sáng tạo trị liệu, tương tự như vũ trị liệu, trị liệu khéo tay (art therapy), và cũng có thể phối hợp với nhiều phương thức trị liệu như thiền, xoa bóp, thôi miên.

Với người khỏe mạnh, âm nhạc được dùng như một phương thức thư giãn, giảm căng thẳng. Ở trẻ em và người lớn có rối loạn về cảm xúc, hành vi, ít khả năng học hỏi, suy giảm các cử động, âm nhạc trị liệu thường được dùng đồng thời với các phương thức trị liệu căn bản để làm bệnh nhân cảm thấy dễ chịu hơn.

Trong phẫu thuật, âm nhạc giúp giảm thiểu cảm giác đau đớn, bớt lo âu sợ hãi, nhanh hồi phục sức lực. Nhiều phụ nữ nhờ thư giãn nghe nhạc mà nhẹ nhàng sinh con không cần đến thuốc tê. Nhiều nghiên cứu cho hay sự kích thích của nhạc điệu đôi khi lấn át được các kích thích tạo ra cảm giác đau, nhờ đó bệnh nhân tập trung vào điệu nhạc và trấn áp được cơn đau.

Bệnh tật có thể khiến cơ thể mệt mỏi, rã rời nhưng khi nghe những điệu nhạc có âm điệu khích lệ, thúc giục, người bệnh có thể quên cả đớn đau, phiền muộn.

Sau cơn tai biến não, nhiều bệnh nhân rơi vào tình trạng mất khả năng vận động, cần tập luyện để phục hồi chức năng. Âm nhạc có vai trò quan trọng giúp bệnh nhân phấn khởi, lần lần mấp máy cử động theo điệu nhạc cũng như giảm thiểu cảm giác buồn chán. Kinh nghiệm cho thấy nhiều người mất tiếng nói lấy lại được phát âm sau khi ầm ừ hát theo nhạc.

Âm nhạc trị liệu được dùng trong các trường hợp: giúp trẻ em tật nguyền khôi phục sự phối hợp các hoạt động thể chất cũng như sự khéo léo của các bắp thịt chân tay; giúp người bệnh sa sút trí tuệ, người có rối loạn hành vi lấy lại sự bình thường trong hành động.

Theo Sức khỏe & đời sống