Archive for the ‘Miscellaneous’ Category

miscellaneous date output (bash)

Monday, April 22nd, 2013

(1)

DATE=`/bin/date --utc "+%Y%m%d%H%M%S"`
echo $DATE

Output : 20130422134138

How add a cronjob under user apache

Thursday, March 22nd, 2012

if you want to setup a cron job under different user or under apache, find out who is the owner of apache process

ps aux | grep apache

in my case the owner of apache process is “daemon”.
now create a cron job under “demon” user

crontab -u daemon -e

Now insert any cron job

* * * * *  cd /usr/local/apache/htdocs/website; /usr/local/bin/php webpage.php  > /dev/null 2>&1

Linux:Iptables rules for different services

Sunday, March 20th, 2011

Bellow information for nfs server:

 vi /etc/sysconfig/nfs
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
MOUNTD_PORT=892
RQUOTAD_PORT=875
STATD_PORT=662
STATD_OUTGOING_PORT=2020

Now reboot the services

# service portmap restart
# service nfs restart
# service rpcsvcgssd restart

Now add rules into iptables

-A RH-Firewall-1-INPUT -s 192.168.2.0/24 -p udp -m udp --dport 111 -j ACCEPT
-A RH-Firewall-1-INPUT -s 192.168.2.0/24 -p tcp -m tcp --dport 111 -j ACCEPT
-A RH-Firewall-1-INPUT -s 192.168.2.0/24 -p tcp -m tcp --dport 2049 -j ACCEPT
-A RH-Firewall-1-INPUT -s 192.168.2.0/24 -p tcp -m tcp --dport 32803 -j ACCEPT
-A RH-Firewall-1-INPUT -s 192.168.2.0/24 -p udp -m udp --dport 32769 -j ACCEPT
-A RH-Firewall-1-INPUT -s 192.168.2.0/24 -p tcp -m tcp --dport 892 -j ACCEPT
-A RH-Firewall-1-INPUT -s 192.168.2.0/24 -p udp -m udp --dport 892 -j ACCEPT
-A RH-Firewall-1-INPUT -s 192.168.2.0/24 -p tcp -m tcp --dport 875 -j ACCEPT
-A RH-Firewall-1-INPUT -s 192.168.2.0/24 -p udp -m udp --dport 875 -j ACCEPT
-A RH-Firewall-1-INPUT -s 192.168.2.0/24 -p tcp -m tcp --dport 662 -j ACCEPT
-A RH-Firewall-1-INPUT -s 192.168.2.0/24 -p udp -m udp --dport 662 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

Selinux commands for services

Saturday, March 5th, 2011

(a)Selinux Requirement for NIS Clients

setsebool -P allow_ypbind=1 ypbind_disable_trans=1 yppasswdd_disable_trans=1

Use getsebool command to verify :

getsebool allow_ypbind ypbind_disable_trans yppasswdd_disabled _trans

allow_ypbind -> on
ypbind_disable_trans –>on
yppasswdd_disable_trans –> on

b) Selinux for vsftpd

getsebool -a | grep ftp
allow_ftpd_anon_write --> off
allow_ftpd_full_access --> off
allow_ftpd_use_cifs --> off
allow_ftpd_use_nfs --> off
ftp_home_dir --> off
httpd_enable_ftp_server --> off
tftp_anon_write --> off

allow user to read and write to their own home directory

setsebool -P ftp_home_dir 1

(c) Selinux for Samba Share

If you want to share /data via samba

chcon -R -t samba_share_t /data

If you want to share home directory

setsebool -P samba_enable_home_dirs 1

Linux:Unable to copy long( _ ,#) file name from windows to samba server

Tuesday, October 5th, 2010

Some times , When trying to copy long directories/subdirectories or file name include (_ or # ) from windows to Samba server, it gives error example : “unable to copy” or “Cant move folder file_name_long_name.cfm ,the file name or extension is too long”

The solution is :

[ share ]
         path = /share-name /long-directory
         read only = no
         case sensitive = True
         default case = upper
         preserve case = no
         short preserve case = no

after Edit, please reboot the server

Linux:How to run c program in linux

Friday, June 4th, 2010

1. Open an editor in linux Example vi editor
2. Write a simple program and save it as progra1.c

  #include <stdio.h>
  int main (void)
{
printf ("Programming is fun.\n");
return 0;
}

3. compile the program : $ gcc prog1.c
4. Run the program : ./a.out
Or
5.you can give it a different name : gcc prog1.c –o prog1
Now run the program by typing : prog1

Linux :file and directory permission

Thursday, April 8th, 2010

Octal Permission:

0 — 000 All types of access are denied
1 –x 001 Execute access is allowed only
2 -w- 010 Write access is allowed only
3 -wx 011 Write and execute access are allowed
4 r– 100 Read access is allowed only
5 r-x 101 Read and execute access are allowed
6 rw- 110 Read and write access are allowed
7 rwx 111 Everything is allowed

Linux-Memory Performance statistics

Wednesday, March 31st, 2010

Ref: Optimizing Linux® Performance: A Hands-On Guide to Linux® Performance Tools

Ref:http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/admin-primer/s1-resource-what-to-monitor.html

Ref:http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/admin-primer/s1-resource-rhlspec.html

Basic explanation of memory related words:

Swap (Not Enough Physical Memory)

All systems have a fixed amount of physical memory in the form of RAM chips.
The Linux kernel allows applications to run even if they require more memory
than available with the physical memory.The Linux kernel uses the hard drive
as a temporary memory. This hard drive space is called swap
space.

Buffers and Cache (Too Much Physical Memory)

 if your system has much more physical memory than required by your applications,
Linux will cache recently used files in physical memory so that subsequent accesses to that file do
not require an access to the hard drive. This can greatly speed up applications that access the hard
drive frequently, which, obviously, can prove especially useful for frequently launched applications.
Note :  most tools that report statistics about “cache” are actually referring to
disk cache.

Buffer:

In addition to cache, Linux also uses extra memory as buffers. To further optimize applications,
Linux sets aside memory to use for data that needs to be written to disk. These set-asides are called
buffers. If an application has to write something to the disk, which would usually take a long time,
Linux lets the application continue immediately but saves the file data into a memory buffer. At some
point in the future, the buffer is flushed to disk, but the application can continue immediately.

Low Memory is not always bad thing:

It can be discouraging to see very little free memory in a system because of the cache and buffer
usage, but this is not necessarily a bad thing. By default, Linux tries to use as much of your memory
as possible. This is good. If Linux detects any free memory, it caches applications and data in the
free memory to speed up future accesses. Because it is usually a few orders of magnitude faster to
access things from memory rather than disk, this can dramatically improve overall performance.
When the system needs the cache memory for more important things, the cache memory is erased
and given to the system. Subsequent access to the object that was previously cached has to go out
to disk to be filled.

Active Versus Inactive Memory

Active memory is currently being used by a process. Inactive memory is memory that is allocated
but has not been used for a while. Nothing is essentially different between the two types of memory.
When required, the Linux kernel takes a process’s least recently used memory pages and moves
them from the active to the inactive list. When choosing which memory will be swapped to disk, the
kernel chooses from the inactive memory list.

High Versus Low Memory

For 64bit processor it does not matter  because they can
directly address additional memory that is available in current system
For 32-bit processors (for example, IA32) with 1 GB or more of physical of memory, Linux must
manage the physical memory as high and low memory. The high memory is not directly accessible
by the Linux kernel and must be mapped into the low-memory range before it can be used.

Bottom line is : If system does not use Swap , there is no need to worry about ,but will have to keep on eye : cache, buffer,free ram. Memory Performance monitoring tools as bellow , which provide

* How much swap is being used

* How the physical memory is being used

* How much free ram.

Memory Performance monitoring tools and related commands:

1.vmstat

2.free -m

3.slabtop

4.top ( Press Shift + m )

5. Ps command

6.procinfo ( yum install procinfo)

6.sar [-B -W -r] ( sysstat packages, yum install sysstate)

Vmstat uses :

 vmstat [-a] [-s] [-m]

vmstat command line options :

-a This changes the default output of memory statistics to indicate the active/
inactive amount of memory rather than information about buffer and cache
usage.
-s  This prints out the vm table. This is a grab bag of differentstatistics about the
system since it has booted. It cannot be run in sample mode. It contains both
memory and CPU statistics.
-m This prints out the kernel’s slab info. This is the same information that can be
retrieved by typing cat/proc/slabinfo. This describes in detail how the
kernel’s memory is allocated and can be helpful to determine what area of the
kernel is consuming the most memory.

Memory Specific vmstat Output statistics swpd:

The total amount of memory currently swapped to disk.
free The amount of physical memory not being used by the operating system or
applications.

buff:

The size (in KB) of the system buffers, or memory used to store data waiting
to be saved to disk. This memory allows an application to continue execution
immediately after it has issued a write call to the Linux kernel (instead of
waiting until the data has been committed to disk).

cache :

The size (in KB) of the system cache or memory used to store data previously
read from disk. If an application needs this data again, it allows the kernel to
fetch it from memory rather than disk, thus increasing performance. &lt;/pre&gt;

active:

 The amount of memory actively being used. The active/ inactive statistics are
orthogonal to the buffer/cache; buffer and cache memory can be active and

inactive:

inactive The amount of inactive memory (in KB), or memory that has not been used
for a while and is eligible to be swapped to disk.

si

:

 The rate of memory (in KB/s) that has been swapped in from disk during the
last sample.

so :

The rate of memory (in KB/s) that has been swapped out to disk during the last
sample.

pages paged in

:

 The amount of memory (in pages) read from the disk(s) into the system buffers.
(On most IA32 systems, a page is 4KB.)

pages paged out :

 The amount of memory (in pages) written to the disk(s) from the system cache.
(On most IA32 systems, a page is 4KB.)

pages swapped in

:

 The amount of memory (in pages) read from swap into system memory.

pages swapped in/out :

 The amount of memory (in pages) written from system memory to the swap.

used swap :

 The amount of swap currently being used by the Linux kernel.

free swap:

 The amount of swap currently available for use.

total swap

:

 The total amount of swap that the

Free Command free can be invoked using the following command line:

free [ -l] [-t] [-s delay ] [-c count ]

Output :

[root@sandbox ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           375        355         19          0        177         86
-/+ buffers/cache:         91        283
Swap:         2000          0       2000

Total:

 This is the total amount of physical memory and swap.

Used

This is the amount of physical memory and swap in use.

Free

 This is the amount of unused physical memory and swap.

Shared

 This is an obsolete value and should be ignored.

Buffers

This is the amount of physical memory used as buffers for disk writes.

Cached

This is the amount of physical memory used as cache for disk reads.

-/+ buffers/cache

 In the Used column, this shows the amount of memory that would be used if
buffers/cache were not counted as used memory. In the Free column, this
shows the amount of memory that would be free if buffers/cache were counted
as free memory.

Low

The total amount of low memory or memory directly accessible by the kernel.

High

The total amount of high memory or memory not directly accessible by the
kernel.

Totals

This shows the combination of physical memory and swap for the Total,
Used, and Free columns.

Sar Command
sar can be invoked with

 sar [-B] [-r] [-R]

Sar Command line options

-B

This reports information about the number of blocks that the kernel swapped

to and from disk. In addition, for kernel versions after v2.5, it reports information about the number of page faults.
-W

This reports the number of pages of swap that are brought in and out of the system.

-r

 This reports information about the memory being used in the system. It includes
information about the total free memory, swap, cache, and buffers being used

Explanation of Sar -B output

pgpgin/s:-    The amount of memory (in KB) that the kernel paged in from disk.
pgpgout/s:-  The amount of memory (in KB) that the kernel paged out to disk.
fault/s:-       The total number of faults that that the memory subsystem needed to fill. These
may or may not have required a disk access.
maj flt/s:-    The total number of faults that the memory subsystem needed to fill and required a disk access.
pswpin/s:-    The amount of swap (in pages) that the system brought into memory.

Explanation of Sar -W output:

pswpout/s:-    The amount of memory (in pages) that the system wrote to swap.
kbmemfree:-    This is the total physical memory (in KB) that is currently free or not being
used

Explanation of Sar -r output :

 
kbmemused:-   This is the total amount of physical memory (in KB) currently being used.
%memused:-   This is the percentage of the total physical memory being used.
kbbuffers:-     This is the amount of physical memory used as buffers for disk writes.
kbcached:-     This is the amount of physical memory used as cache for disk reads.
kbswpfree:-    This is the amount of swap (in KB) currently free.
kbswpused:-   This is the amount of swap (in KB) currently used.
%swpused:-   This is the percentage of the swap being used.
kbswpcad:-    This is memory that is both swapped to disk and present in memory. If the
memory is needed, it can be immediately reused because the data is already
present in the swap area.
frmpg/s:-       The rate that the system is freeing memory pages. A negative number means
the system is allocating them.
bufpg/s:-       The rate that the system is using new memory pages as buffers. A negative
number means that number of buffers is shrinking, and the system is using less
of them

Linux:If Running Kernel Is 32 Or 64 Bit

Thursday, February 18th, 2010

To find out, if Your kernel is 64 bit or 32 bit, run this commands

uname -a

Sample Out put for 64 bit kernel :

Linux  2.6.16.53-070731a #1 SMP Tue Jul 31 10:46:54 CEST 2007 x86_64 x86_64 x86_64 GNU/Linux

here x86_64 GNU/Linux indicates this kernel is 64 bit.

Sample Output for 32 bit kernel :

Linux sandbox.hostname.local 2.6.18-164.11.1.el5 #1 SMP Wed Jan 20 07:39:04 EST 2010 i686 i686 i386 GNU/Linux

here i386 GNU/Linux indicates its a 32 bit kernel, also if you see i386/i486/i586/i686 which indicates its 32 bit kernel

also:
How to find if processor is 32 bit or 64 bit:
ref : http://fosiul.com/index.php/2010/02/linux-how-to-conferm-64bit32bit-capability-of-cpu/

Additional repository list for 32 bit kernel and 64 bit kernel
http://fosiul.com/index.php/2009/12/yum-repo-list-for-centos/

Linux-How to conferm 64bit/32bit capability of CPU

Wednesday, February 17th, 2010

How many CPU in the system :

commands : cat /proc/cpuinfo

 
[root@server ~]# cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 15
model           : 4
model name      : Intel(R) Xeon(TM) CPU 3.40GHz
stepping        : 3
cpu MHz         : 3401.008
cache size      : 2048 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 1
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 5
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl est cid xtpr
bogomips        : 6805.07
 
processor       : 1
vendor_id       : GenuineIntel
cpu family      : 15
model           : 4
model name      : Intel(R) Xeon(TM) CPU 3.40GHz
stepping        : 3
cpu MHz         : 3401.008
cache size      : 2048 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 1
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 5
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl est cid xtpr
bogomips        : 6799.15
 
processor       : 2
vendor_id       : GenuineIntel
cpu family      : 15
model           : 4
model name      : Intel(R) Xeon(TM) CPU 3.40GHz
stepping        : 3
cpu MHz         : 3401.008
cache size      : 2048 KB
physical id     : 3
siblings        : 2
core id         : 3
cpu cores       : 1
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 5
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl est cid xtpr
bogomips        : 6799.30
 
processor       : 3
vendor_id       : GenuineIntel
cpu family      : 15
model           : 4
model name      : Intel(R) Xeon(TM) CPU 3.40GHz
stepping        : 3
cpu MHz         : 3401.008
cache size      : 2048 KB
physical id     : 3
siblings        : 2
core id         : 3
cpu cores       : 1
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 5
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl est cid xtpr
bogomips        : 6799.40
 
[root@server ~]#

From the example above there is 4 processor in the system [ processor 0 …. processor 3]

also :

short cut : cat /proc/cpuinfo  | grep processor
processor       : 0
processor       : 1
processor       : 2
processor       : 3


How to find out if processors are 64bit or 32 bit

From the out put cat /proc/cpuinfo, look at the flags column, if there is a word call lm , that means its
a 64bit processor.

Short cut commands :
grep flags /proc/cpuinfo

output :

[root@server ~]# grep flags /proc/cpuinfo
flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl est cid xtpr
flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl est cid xtpr
flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl est cid xtpr
flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl est cid xtpr

From the output above, all four processors has lm word, which means its 64 bit processors
if you do not see lm word, then its 32 bit processor.

Invalid method in request \x80O\x01\x03

Wednesday, November 18th, 2009

Make sure the IP of the server and the Ip in Virutal host (ssl configuraiton ) are same.

<VirtualHost xx.xx.xx.xx:443>

</VirtualHost>