Thursday, January 1, 2015

Linux - Commands


ps -aef | grep 'mongo' | grep -v grep | awk '{print $2}
 
Recursive Grip in all Directory in this location
  
grep -r -i "word to search" *
:%s/\/apps/oracle/new/g
watch -n 10 'ls -ltr'
watch -n 10 a.sh

SCAN DIsks , SCAN DISK

root#> ls /sys/class/scsi_host
root#> echo "- - -" > /sys/class/scsi_host/hostNNNN/scan

-- Example
root#> echo "- - -" > /sys/class/scsi_host/host0/scan


------------ Mount /dev/sgm to Increase SGA

mount -t tmpfs shmfs -o size=(Value Greater than value of Memory_target) /dev/shm

mount -t tmpfs shmfs -o size=5g /dev/shm

Linux Version
----------------
cat /etc/redhat-release

Command to generate dummy file

time dd if=/dev/zero of=test.bin bs=1000000000 count=1

Who and What is doing What on Your System - finding open sockets,files etc.
$ lsof
or as root
$ watch lsof -i

Also try fuser. Suppose you have a mounted file-system, and you need  to umount it. To list the users on the file-system /work
$ fuser -u /work
To kill all processes accessing the file system /work  in  any way.
$ fuser -km /work


Need a listing of the system settings?
$ sysctl -a


RPM
=================
rpm -qa --queryformat "%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n" | grep unixODBC
 
=======================
SAR ( Good )
=======================
Sar Collects every 10 Min the history of system and saves file  /var/log/sarDATE 
regarding CPU, Processes , Disk Read Write, Load , Memory, Buffers, IO statistics, Interface Cards Stats


To check the history of sar
 
=======================
Networking ( Good )
=======================
 
dmesg | grep eth0 --> speed of network

route -nr

ifup eth0/eth1/eth1 

mii-tool -v

ethtool eth0 --> gives details about eth

netstat -nr

-- use this good one
 
netstat -nap

how to change gateway  /etc/sysconfig/network

eth scripts
 
/etc/sysconfig/network-scripts/eth*

How Many Interfaces are defined
 
ip link show
 
/sbin/ifconfig -a
 
netstat -I
 
How to rename the Interface
 
ip link set eth3 down
ip link set eth3 name eth1
ip link set eth1 up
 
=======================
Users Groups and sudo 
=======================
-->To determine whether the oinstall group exists, enter the following command:
 
      # grep oinstall /etc/group
      If the output from this command shows the specified group name, that group already exists.
      If necessary, enter the following command to create the oinstall group:
      # /usr/sbin/groupadd oinstall

-->  To determine whether the oracle user exists and belongs to the correct groups, enter the following command:
 
      # id oracle
      If the oracle user exists, this command displays information about the groups to which the user belongs. 
      uid=502(oracle) gid=502(oinstall) groups=502(oinstall),503(dba)

-->  If necessary, complete one of the following actions:
            If the oracle user exists, but its primary group is not oinstall, enter a command similar to the following, where the -g option specifies oinstall as the primary group and the -G option specifies any existing groups to which the oracle user belongs:
            # /usr/sbin/usermod -g oinstall -G dba oracle
          If the oracle user does not exist, enter the following command to create it:
            # /usr/sbin/useradd -g oinstall -G dba oracle
            This command creates the oracle user and specifies:
                  oinstall as the primary group
                  dba as an optional secondary group
-->  Enter the following command to set the password of the oracle user:
      # passwd oracle

-->  how to make Sudo from Oracle to Root
 usermod -G root useraccount
 Add this to your /etc/sudoers file.
 oracle ALL= NOPASSWD: ALL

Current Kernal Used
-------------------
1) uname -r
2) cat /proc/version
3) rpm -q kernel


You can list all kernel modules that are currently loaded into the kernel by running the lsmod 
$lsmod

Each row of lsmod output specifies: 
the name of a kernel module currently loaded in memory; 
the amount of memory it uses;  
the sum total of processes that are using the module and other modules which depend on it, 
followed by a list of the names of those modules, if there are any. 

look in directories in which the kernel or its source code (i.e., the original version as written by humans in a programming language) is kept.
ls /boot

How to check All loaded Modules in Memory 
-----------------------------------------
$lsmod

How to check the Module info
------------------------------
$modinfo <modulename>    <-- list all modules by issuing $lsmod
Example $modinfo ocfs2_dlm


Loading a Module
----------------
To load a kernel module, run modprobe <module_name>  as root. 
For example, to load the wacom module 
# modprobe wacom

You can use the -v (or --verbose) option to cause modprobe to display detailed information about what it is doing,

$modprobe -v fcoe

By default, modprobe attempts to load the module from /lib/modules/<kernel_version>/kernel/drivers/. 
In this directory, each type of module has its own subdirectory, such as net/ and scsi/, 
for network and SCSI interface drivers respectively. 


Unloading a Module
------------------
modprobe -r -v wacom  <- Example unload wacom

Note:Unload may fail if module is being used so you may have to stop others


service command - list running services
service --status-all
service --status-all | grep ntpd
service --status-all | less
Print the status of any service
To print the status of apache (httpd) service:
service httpd status
List all known services (configured via SysV)
chkconfig --list
List service and their open ports
netstat -tulpn
Turn on / off service
ntsysv
chkconfig service off
chkconfig service on
chkconfig httpd off
chkconfig ntpd on


mount /dev/mpath/mpath17p1 /export

Mount Manually /list Logical Volumes

mount /dev/mpath/mpath17p1 /export
vdisplay - display attributes of a logical volume

File bigger than Certain Size


find / -type f -size +100000k -exec ls -lh {} \; 
find / -type f -size +100000k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'

List Volumes

lvm pvs

FindDisk UUID and Lables

root#blkid
Example
root@dbaovm06:/usr/sbin# blkid
/dev/xvda1: LABEL="boot" UUID="718c1709-9431-465f-b5e6-14a9a4d75b4e" TYPE="ext4"
/dev/xvdb1: LABEL="D_DG_VOTE" TYPE="oracleasm"
/dev/xvdb13: UUID="85dbb460-6cd8-4d1d-8aeb-ba8f431a6096" TYPE="ext3"

Delete files older than x days



-- Using exec ( Deleting anything older tthan 15 Days)
find /export/oracle/*.dmp -mtime +15 -exec rm () ;

-- Using xargs ( Good in scripts)
find /export/oracle/ -type f -name "*.dmp" -mtime +5 | xargs rm --force;
Other Examples and Usages

for alert file, 
find $ORACLE_BASE/admin/$ORACLE_SID/bdump -ctime +60 -name alert_$ORACLE_SID.log -exec rm {} \;

listener file,
find $ORACLE_HOME/network/log -name listener.log -ctime +14 -exec rm {} \;

sqlnet file,
find $ORACLE_HOME/network/log -name sqlnet.log -ctime +14 -exec rm {} \;


for i in *; do 
 rm -f $i; 
done
for i in $(echo *); do 
 echo "Deleting : $i"; rm -f $i; 
done


linux/LinuxMemory/Memory/Disk/CPU Usage File etc iostat


============
Disk Usage  
============

du -sk * | sort -n   ( will give summary of all sub Directory in KB  , Best Command )

-- now to get inside the subdire use this
du | sort -g     Gives Total Size of Directory and Sub Directory


du -x | sort -n 

du - -max-depth=1 
du - -max-depth=3 | sort -n -h | more 
du /apps --max-depth=2 -h | sort -n

============
Momory
============
if we are doing swaping run this following and watch for si , so  ( swap in Swap out memory)
vmstat 3 100

$ mpstat  
$ mpstat -P ALL 
$ vmstat 3
$ ps aux  (will show memory used by individual process)

Extended extended statistics including disk utilization 
$ iostat -x 10
$ iostat -xtc 5 3  
$ top 
$free  -- find memoray usage switch -m -t -v etc



adarshkumar@oramo18:~$ cat /proc/meminfo

MemTotal:     98989996 kB
MemFree:        460516 kB
Buffers:         37716 kB
Cached:       37386488 kB
SwapCached:    1972088 kB
Active:       39525724 kB
Inactive:       934080 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:     98989996 kB
LowFree:        460516 kB
SwapTotal:    33551744 kB
SwapFree:     20437724 kB
Dirty:            6100 kB
Writeback:           0 kB
AnonPages:     1500208 kB
Mapped:       36941076 kB
Slab:           869692 kB
PageTables:    3498336 kB
NFS_Unstable:        0 kB
Bounce:              0 kB
CommitLimit:  56422740 kB
Committed_AS: 56838048 kB
VmallocTotal: 34359738367 kB
VmallocUsed:    300564 kB
VmallocChunk: 34359437627 kB
HugePages_Total: 26000
HugePages_Free:  26000
HugePages_Rsvd:      0
Hugepagesize:     2048 kB



============
cpu info 
============
$ cat proc/cpuinfo

hardwre into look in /etc directory

items
svctm - average service time

mpstat -P ALL

$sar    -- will list  current plus  todays all history in every 10 Min ( excellent Command)

sar -u 2 3   -- 2 seconds apart 3 times


who is eating cpu
----------------


ps -eo pcpu,pid,user,args | sort -r -k1 | less 
or
ps -eo pcpu,pid,user,args | sort -r -k1 | less  


$ gnome-system-monitor

============
Sort a file
============
to sort a file named foo with numbers and letters at the beginning of lines, and display the result omitting duplicate entries try this:
[ sort -u foo ] 

or send the output to a file named sorted_file1:
[ sort -u foo > sorted_file1 ]

 wc foo 
 wc -c foo - print the byte count in the foo file
 wc -m foo - print the number of characters in the foo file
 wc -l foo - print the number of lines in the foo file
 wc -L foo - print the length of the longest line in the foo file
 wc -w foo - print the word count for the file called foo

remove duplicate lines from file
uniq 



============
IOSTAT
============

iostat -x 10 | grep emc

iostat -x 10 -d <disk1> <disk2> <disk3>     -- this will list these disks

example
Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
dm-0              0.00     0.00  611.40  414.23 20286.60  1656.93 42.79    17.50   17.33   0.96  98.57

r/s and w/s: number of read and write requests issued per second to the device (in this case 611 and 414)
rsec/s and wsec/s – number of sectors read/written per second
rkB/s and wkB/s – number of kilobytes read/written per second

avgrq-sz – average number of sectors per request (for both reads and writes). ie (rsec + wsec) / (r + w)
avgqu-sz – average queue length in the monitoring interval (in this case 42.79)
await – average time that each IO Request took to complete. This includes the time that the request was waiting in the queue and the time that the request took to be serviced by the device

svctim – average time each IO request took to complete  during the monitoring interval
Note: await includes svctim. Infact await (average time taken for each IO Request to complete) = the average time that each request was in queue (lets call it queuetime) PLUS the average time each request took to process (svctim)

%util: This number depicts the percentage of time that the device spent in servicing requests. This can be calculated with the above values. In the above example the total number of reads and writes issued per second is 611 + 414 => 1025. Each request takes 0.96 ms to process. Therefore 1025 requests would take 1025 x 0.96 => 984 ms to process. So out of the 1 second that these requests were sent to the device in, 984 ms were taken to process the requests. This means the device utilization is 984/1000 * 100 => ~98.4%. As you can see in the above iostat output the %util does show ~ 98.5%


Example 2
----------

Interpreting iostat values

Lets take the above example

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
dm-0              0.00     0.00  611.40  414.23 20286.60  1656.93 42.79    17.50   17.33   0.96  98.57

avg time that each request spent in queue (qtime) = await – svctime = 17.33 – 0.96 => 16.37 ms
avg time tha each request spent being serviced = 0.96 ms
so averagely each IO request spent 17.33ms to et processed of which 16.37 ms were spent just waiting in queue
%util can be calculated as (r/s + w/s) * svctim / 1000ms * 100  => 1025*0.96/1000 * 100 => 98.5%
This simple means that in a 1 second interval, 1025 requests were sent to disk, each of which took 0.96ms for the disk to process resulting in 984 ms of disk utilization time in a period of 1 s (or 1000 ms). This means the disk is greater than 98% utilized
On this disk subsystem, it is clear that the disk cannot process more IO requests than what it is getting

Lets take another example -

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
sdb               6.33   139.07   46.30   19.53   526.27   634.40    35.26 0.54    8.17   3.30  21.74

avg time that each request spent in queue (qtime) = await – svctime = 8.17 – 3.30 => 4.87 ms
avg time tha each request spent being serviced = 3.30 ms
so averagely each IO request spent 8.17 ms to et processed of which 4.87 ms (a little more than half) were spent waiting in queue
%util can be calculated as (r/s + w/s) * svctim / 1000ms * 100  => 65.83 * 3.3/1000 * 100 => 21.72%
This simple means that in a 1 second interval, 65 requests were sent to disk, each of which took 3.30ms for the disk to process resulting in 217 ms of disk utilization time in a period of 1 s (or 1000 ms). This means the disk is around 21.7 % utilized
On this disk subsystem, it is clear that the disk is not fully utilized. While due to the nature of the requests, averagely requests are spending half their time in queue, that is not so bad. This disk subsystem is capable of greater throughput.


</code >
 

====== OID ======

===== Compare Entries in two OID's =====

 /apps/oracle/OraHome_1/ldap/bin/oidcmprec operation=compare source=oraoidm01:389/<oidpassword> destination=oraoidv01:389/cfxoid12 base='("ou=Virginia,dc=carfax,dc=cfx")' scope=sub \\

===== ldapsearch Example =====

List all UID's which have Email like adarsh \\
ldapsearch -h oraoidm01 -D "cn=orcladmin" -w cfxoxxxx -b "dc=carfax,dc=cfx" -s sub "mail=adarsh*"  uid; \\

If you want multiple attributes returned, list the attribute names separated by spaces: \\
ldapsearch -D "cn=orcladmin" -w welcome -s sub -b "o=com" "mail=dave@oracle.com" mail title   \\

ldapsearch  -h oramotest01.lab.cfx -p 3060 -D "cn=orcladmin" -w "welcome1"  -b "cn=Users,dc=lab,dc=cfx" -s sub  "cn=test3"

ldapsearch -p 389 -h ora-ldap1 -w "?????" -b "" -s sub  "objectclass=*"

-- following example searches for attribute "givename" in the entire objectClass starting from base "cn=test,..."

ldapsearch -p 389 -h ora-ldap1 -w "????" -b "cn=test,cn=users,dc=ora-ldap1,dc=com" -s sub  "objectclass=*" givenname


===== SysContext Query =====

select sys_context ('userenv' , 'external_name') from dual;

===== Changing User to Global User =====
<code>
AS sys in dcfxm and tcfxm 
create user adarshkumar identified globally as 'cn=adarsh kumar,ou=dba,ou=dept_users,ou=missouri,dc=carfax,dc=cfx';  
grant connect,resource to adarshkumar; 
adarshkumar/test1@dcfxm

alter user danielsmith  identified globally as 'cn=daniel smith,ou=dba,ou=portable users,ou=dept_users,ou=missouri,dc=carfax,dc=cfx';
alter user kurtguisti   identified globally as 'cn=kurt guisti,ou=dba,ou=portable users,ou=dept_users,ou=missouri,dc=carfax,dc=cfx';
alter user dankenney    identified globally as 'cn=dan kenney,ou=dba,ou=portable users,ou=dept_users,ou=missouri,dc=carfax,dc=cfx';
alter user brucehassler identified globally as 'cn=bruce hassler,ou=dba,ou=dept_users,ou=missouri,dc=carfax,dc=cfx';

grant connect,resource to kurtguisti;
grant connect,resource to danielsmith;



##########################################################################
Create a Soft or link between the Directories
##########################################################################
Situation :We have 2 databases with the Wallet Directory and files
we Want to move the Wallet to a Common Location /deploy/database_wallet/
==========================================================================
/apps/oracle/product/11.2.0/db/admin/DB1/wallet/
                                             -- a.txt
                                                                                            -- b.txt
/apps/oracle/product/11.2.0/db/admin/DB2/wallet/
                                         --c.txt
                                              -- d.txt
Desired(Complete Directory and Contents should mapped to /deploy/database_wallet/
============================================================================
It should look like this
/apps/oracle/product/11.2.0/db/admin/DB1/wallet -> /deploy/database_wallet/DB1/wallet 
/apps/oracle/product/11.2.0/db/admin/DB2/wallet -> /deploy/database_wallet/DB2/wallet
Work
=============================================================================             1) Create directories to the New Location which is /deploy & Change the Permissions
    mkdir -p /deploy/database_wallet/DB1/wallet
    mkdir -p /deploy/database_wallet/DB2/wallet
2) Copy original files which to the new Location 
   copy  a.txt, b.txt to /deploy/database_wallet/DB1/wallet
  copy  c.txt, d.txt to / deploy/database_wallet/DB2/wallet
3) Now we have this
/deploy/database_wallet/DB1/wallet/
                                                                         -- a.txt
                                                                         -- b.txt
 /deploy/database_wallet/DB2/wallet/
                                                                         -- c.txt
                                                                        -- d.txt
4) Now time to remove the Old Location (ONLY WALLET) and
Map it to the New one
rm -rd /apps/oracle/product/11.2.0/db/admin/DB1/wallet
rm -rd /apps/oracle/product/11.2.0/db/admin/DB2/wallet
Now the Old Location do not have wallet Directory at all
Time to create a Directory with the Link 
ln -s /deploy/database_wallet/DB1/wallet    /apps/oracle/product/11.2.0/db/admin/DB1/wallet
ln -s /deploy/database_wallet/DB2/wallet    /apps/oracle/product/11.2.0/db/admin/DB2/wallet
Now Checking
 ls -l /apps/oracle/product/11.2.0/db/admin/DB1
 lxxx xxx xxx / apps/oracle/product/11.2.0/db/admin/DB1/wallet -> /deploy/database_wallet/DB1/wallet