Thursday, September 15, 2011

the Linux rights of files and directory


 
1. the "file1" can be a file or directory

          |---- owner
          ||----- group
          |||------- other users
   chmod  467  file1    
  
   1 = Execute
   2 = Write
   4 = Read
  
   3 = 2+1   can Write, Execute
   5 = 4+1   can Read, Execute
   6 = 4+2   can Read, Write
   7 = 4+2+1 can Read, Write, Execute



Basic vi Commands

Copy line               yy
Copy next n line        Nyy (N is number of lines to be copy)
Past line               p
Insert before cursor    i
Insert current line     I
Replace                 R
Delete                  [Delete]
Delete Line             dd
Undo                    u
                       
Page Up                 [Ctrl] + b
Page Down               [Ctrl] + f
To Begin of file        :0 or 1G
To End of file          :$ or G
Move To n line          :nG (n is number of line)
Move beginning of line  0
Move end of line        $


Search forward string   /string
Search backward string  ?string
to next match string    n
to prev match string    N


Save                    :w
Save and Exit           :x or :wq
Exit                    :q
Exit without save       :q!

How to install Samba CentOS

Install samba
# yum install samba

Configure samba
# vi /etc/samba/smb.conf
[global]
workgroup = Linux
netbios name = CentOS_Srv
;name resolve order = bcast host lmhosts wins
server string = CentOS Samba v.%v
security = user
passdb backend = tdbsam

[www]
comment = Public WWW
path = /var/www
create mask = 0660
directory mask = 0771
writable = yes
valid users = user1 user2

Add User for samba
# useradd user1 -d /mnt/data/home/user1
# chown user1:user1 /mnt/data/home/user1
# passwd user1
#     Enter your password
# smbpasswd -a user1


# /etc/init.d/smb restart

Configure Firewall for samba
Change IPTables
# vi /etc/sysconfig/iptables
#Includes the following before the REJECT line:
-A INPUT -p udp -m udp --dport 137 -j ACCEPT
-A INPUT -p udp -m udp --dport 138 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT

# service iptables restart


Run samba when OS starting
# chkconfig --levels 235 smb on


Client test
net use  Z: \\192.168.6.2\www /user:user1


http://wiki.centos.org/HowTos/SetUpSamba 



Wednesday, September 14, 2011

Config Network Adapter for CentOS Linux


vi /etc/sysconfig/network-scripts/ifcfg-eth0

#####################################
# for static ip
#DEVICE="eth0"
#BOOTPROTO="static"
#HWADDR="00:30:48:56:A6:2E"
#IPADDR="10.1.1.5"
#NETMASK="255.255.255.192"
#ONBOOT="yes"

#####################################
# for dhcp ip
DEVICE="eth0"
BOOTPROTO="dhcp"
ONBOOT="yes"


vi /etc/sysconfig/network
NETWORKING=yes

# for static ip
#HOSTNAME=host1.mysite.com
#GATEWAY=10.1.1.1

ifdown eth0
ifup eth0

or /etc/init.d/network restart

Monday, September 5, 2011

Using comparison operators in a unsafe way

// Using operators in a unsafe way

// declare a variable to null
string s = null;
// for the 'or'  operator comparison
// if left side get true the right side will never be invoke
// if left side get false, the right side will come.
// in this example below will be fine because the right side won't be invoke when
left side is true.
if(s == null || s.Length == 0)

// for 'and' operator comparison
//
if left side get true the right side will invoke
// if left side get false the right side will never invoke
// this example below will be throw a exception while right side is execute.

if(s == null && s.Length == 0)


// declare functions
func1(param){return param;}
func2(param){return param;}

//                                                which function being call
if(func1(true) && func2(true))     func1   func2
if(func1(false) && func2(true))    func1
if(func1(true) || func2(true))         func1
if(func1(false) || func2(true))        func1   func2


// the concept above can also apply to C/C++, java and javascript ....

Thursday, September 1, 2011

Change IP Address Using Netsh.exe Command

Netsh command
Applies To: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1, Windows Server 2003 with SP2


to change the ipv4 address, subnet mask and getway
netsh int ipv4 set address "Local Area Connection" static 192.168.0.2 255.255.255.0 192.168.0.254 1

to change DNS
netsh int ip set dns "
Local Area Connection" static 192.168.0.254 primary


The "Local Area Connection" is your Adapter name, It could also be "local area connection 2" or "wireless network connection"...




Syntax
netsh int ipv4 set address [name=]InterfaceName [source=]{dhcp | static [addr=]IPAddress[mask=]SubnetMask [gateway=]{none | DefaultGateway [[gwmetric=]GatewayMetric]}}
 

MSDN Document

Tuesday, August 2, 2011

javascript undefined

var a;
var b = null;
var c = "";
// d is not declare



//  var a;
typeof(a)                           return undefined
a == undefined                 return true
a === undefined               return true

// var b = null;
typeof(b)                           return object
b == undefined                 return true
b === undefined               return false

// var c = "";
typeof(c)                           return string
c == undefined                 return false
c === undefined               return false

// d is no declare
typeof(d)                           return undefined
d == undefined                 throw exception
d === undefined               throw exception