Jan 31, 2015

Usefull Unix/ Linux / AIX commands

1) Few Find commands:

Use find command, find all *.txt files but ignore foo.txt
$ find . -type f \( -iname "*.txt" ! -iname "foo.txt" \)

To delete file add -delete or -exec your-delete-command-here option.
$ find . -type f \( -iname "*.txt" ! -iname "foo.txt" \) -delete

To select folder or dirs use -type d, in this example, find all folders and ignore foo and bar folder :
$ find . -type d \( ! -iname "foo" ! -iname "bar" \)

To delete folders except foo and bar
$ find . -type d \( ! -iname "foo" ! -iname "bar" \) -execdir rm -rfv {} +

2) Services ( start/ stop/status):

Example: Verification of FTP services:
-- Verify service status , All services

# service --status-all

-- Specific services

# service vsftpd restart
# service vsftpd status
# service vsftpd stop

-- others ( while restart, you may restart twice also)
# service nfs restart
# service ISCSI restart
# service network restart

Example:
# service vsftpd status
vsftpd is stopped

# service vsftpd start
Starting vsftpd for vsftpd:                                [  OK  ]

# service vsftpd status
vsftpd (pid 32674) is running...

3) Tar / zip 
In order to "zip" a directory, the correct command would be
$ tar -zcvf archive.tar.gz directory/
tar -zxvf archive.tar.gz 
To decompress and unpack the archive into the current directory you would use
Uisng Zip command to zip folder:

$ zip -r OracleExtracts.zip OracleExtracts

4) Free command in Linux:
$ free -t
             total       used       free     shared    buffers     cached
Mem:      25023920   22682680    2341240          0     622276   19597120
-/+ buffers/cache:    2463284   22560636
Swap:     25165816          8   25165808

Total:    50189736   22682688   27507048

 -t display total for RAM + swap

$ free -s 5 
 -s update every [delay] seconds, delay is 5 seconds
 -b,-k,-m,-g show output in bytes, KB, MB, or GB

$ free -g -s 5
             total       used       free     shared    buffers     cached
Mem:            23         21          2          0          0         18
-/+ buffers/cache:          2         21
Swap:           23          0         23

             total       used       free     shared    buffers     cached
Mem:            23         21          2          0          0         18
-/+ buffers/cache:          2         21
Swap:           23          0         23

Swap Activities
Using: $ cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/dm-0                               partition       16777208        176188  -1

CPU per-Processor Statistics
Using: mpstat 5 3

$ mpstat 5 3
Linux 2.6.32-279.el6.x86_64 (apps.com)       Wednesday 18 March 2015         _x86_64_        (8 CPU)

05:17:34  IST  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
05:17:39  IST  all    0.18    0.00    0.10    0.93    0.00    0.03    0.00    0.00   98.77
05:17:44  IST  all    0.15    0.00    0.08    0.35    0.00    0.00    0.00    0.00   99.42
05:17:49  IST  all    0.33    0.00    0.10    0.81    0.00    0.00    0.00    0.00   98.77
Average:     all    0.22    0.00    0.09    0.70    0.00    0.01    0.00    0.00   98.99

CPU Statistics using Top

$ top -help

        top: procps version 3.2.8

usage:  top -hv | -abcHimMsS -d delay -n iterations [-u user | -U user] -p pid [,pid ...]


Using: top -d 5 -n 4 b | grep "^Cpu(s):"  
(% seconds interval 4 readings)
top -d 5 -n 4 b | grep "^Cpu(s):"
Cpu(s):  8.9%us,  1.3%sy,  0.0%ni, 88.7%id,  1.2%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu(s):  0.2%us,  0.2%sy,  0.0%ni, 99.1%id,  0.4%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu(s):  0.2%us,  0.2%sy,  0.0%ni, 99.3%id,  0.3%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu(s):  0.4%us,  0.1%sy,  0.0%ni, 99.3%id,  0.2%wa,  0.0%hi,  0.0%si,  0.0%st

5) vi editor commands:

To reach home ( BOF) -   :0  or 1G
To reach end ( EOF)    -   :$  or  G
Page down : ^d
Page up     : ^u
Search string  : [Escape]/string             -- press 'n' to find next
Find&replace : [Escape]/%s/<string_find>/<string_replace/g

6) Mount commands:
-- To mount (nfs)
# mount -o rw,bg,hard,rsize=32768,wsize=32768 160.192.1.2:/u03 /mnt 

 Note: If unable to mount, then use below commands twice
    # service nfs restart
OR
# mount -t nfs 192.168.1.4:/u03 /mnt
-- To mount ocfs

# mount -t ocfs2 -o datavolume /dev/sdb1 /APPS
   Where : datavolue is the disk group volume name, /dev/sdv1 is hard disk specification, /APPS is ocfs mount name

Issues in Linux:

mount.nfs: access denied by server while mounting

Fix :

-- modify in source:

# vi /etc/exports

/u02 172.18.2.8(rw,sync)

:wq

and then apply the same in source
# exportfs -a

Traget:

# cd /
# mkdir u02
# chmod -R 775 u02
# chown -R oracle:oinstall u02


# mount -t nfs -o rw,bg,hard,rsize=32768,wsize=32768,vers=3,nointr,proto=tcp 172.18.2.10:/u02 /u02
OR
# mount -t nfs 172.18.2.10:/u02 /u02


Mount new hard-disk to a linux box:

step-1: check disk attached or not 

[root@EBH-DB4 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda5              20G  320M   19G   2% /
/dev/sda1             5.0G   50M  4.7G   2% /boot
none                  9.9G   55M  9.3G   1% /dev/shm
/dev/sda6             9.9G   55M  9.3G   1% /dev/shm
/dev/sda9             9.9G   61M  9.3G   1% /home
/dev/sda2             197G  179G  8.6G  96% /oracle
/dev/sda8             9.9G  182M  9.2G   2% /tmp
/dev/sda3              20G  6.8G   12G  37% /usr
/dev/sda7             9.9G  257M  9.1G   3% /var


# /sbin/fdisk -l

Disk /dev/sda: 320.0 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         653     5245191   83  Linux
/dev/sda2             654       26761   209712510   83  Linux
/dev/sda3           26762       29372    20972857+  83  Linux
/dev/sda4           29373       38913    76638082+   5  Extended
/dev/sda5           29373       31983    20972826   83  Linux
/dev/sda6           31984       33288    10482381   83  Linux
/dev/sda7           33289       34593    10482381   83  Linux
/dev/sda8           34594       35898    10482381   83  Linux
/dev/sda9           35899       37203    10482381   83  Linux
/dev/sda10          37204       38247     8385898+  82  Linux swap

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/sdc: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       60801   488384001   83  Linux

here -- 1 TB disk attached.

Step-2: format the hard disk with supported file system

-- to find file system:

# cat /etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/                 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
none                    /dev/pts                devpts  gid=5,mode=620  0 0
none                    /dev/shm                tmpfs   defaults        0 0
LABEL=/dev/shm          /dev/shm                ext3    defaults        1 2
LABEL=/home             /home                   ext3    defaults        1 2
LABEL=/oracle           /oracle                 ext3    defaults        1 2
none                    /proc                   proc    defaults        0 0
none                    /sys                    sysfs   defaults        0 0
LABEL=/tmp              /tmp                    ext3    defaults        1 2
LABEL=/usr              /usr                    ext3    defaults        1 2
LABEL=/var              /var                    ext3    defaults        1 2
LABEL=SWAP-sda10        swap                    swap    defaults        0 0

-- Now format the disk with supported file-system(fs)

# /sbin/mkfs.ext3 /dev/sdb
mke2fs 1.35 (28-Feb-2004)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
122109952 inodes, 244190646 blocks
12209532 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
7453 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
        102400000, 214990848

Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@EBH-DB4 /]# 

-- Now mount the disk

Create a directory where you'll mount the new disk, for example /expdp, and mount it there:
mkdir /expdp
mount -t ext3 /dev/sdb /expdp

# mount -t ext3 /dev/sdb /expdp
[root@EBH-DB4 /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda5              20G  320M   19G   2% /
/dev/sda1             5.0G   50M  4.7G   2% /boot
none                  9.9G   55M  9.3G   1% /dev/shm
/dev/sda6             9.9G   55M  9.3G   1% /dev/shm
/dev/sda9             9.9G   61M  9.3G   1% /home
/dev/sda2             197G  179G  8.6G  96% /oracle
/dev/sda8             9.9G  182M  9.2G   2% /tmp
/dev/sda3              20G  6.8G   12G  37% /usr
/dev/sda7             9.9G  257M  9.1G   3% /var
/dev/sdb              917G  104M  871G   1% /expdp
[root@EBH-DB4 /]# pwd
/
# chmod -R 777 /expdp


Recommended mount options for NFS

Table: Mount options for NFS lists the mount options for Network File System (NFS) on Solaris, HP-UX, AIX, and Linux operating systems. The recommendations are for Oracle data files.

Table: Mount options for NFS
Operating System Mount Options for Oracle Datafiles
Solaris
rw,bg,hard,nointr,rsize=1048576
wsize=1048576,proto=tcp,noac,
forcedirectio, vers=3,suid
AIX (5L)
cio,rw,bg,hard,nointr,rsize=1048576,
wsize=1048576,proto=tcp,noac,
vers=3,timeo=600 
HP-UX 11i v3
rw,bg,vers=3,proto=tcp,noac,
forcedirectio,hard,nointr,timeo=600,
rsize=1048576,wsize=1048576,suid
Linux x86
rw,bg,hard,nointr,rsize=1048576,
wsize=1048576,tcp,actimeo=0,
vers=3,timeo=600
Linux x86-64
rw,bg,hard,nointr,rsize=1048576,
wsize=1048576,tcp,actimeo=0,
vers=3,timeo=600

Click here to read more ...

Issues for nfs mounts:
-- hang message in df -g
# df -h
....
....
NFS server 10.33.33.184 not responding still trying

-- Unable to umount
# umount /BACKUP
umount: 1831-015 16 error while unmounting 10.10.1.1:/u01/BACKUP 
The requested resource is busy.

-- Working : Forcefully unmount a filesystem

# umount -f /BACKUP
Warning: umount:: RPC: 1832-018 Port mapper failure - RPC: 1832-008 Timed out
forced unmount of /BACKUP

-- fuser
You can also execute fuser command to find out which process is holding the directory for operations.

# fuser -cu /mydata
/mydata:              3087(root)


7) User Add/ Group Add with specific IDs:

# groupadd -g 5001 dba
# useradd -g dba -d /u01 -u 5002 oracle
# useradd -g dba -d /u02 -u 5003 applmgr

-- Assign groups and giving perissions
# chown -R oracle:dba /u01
# chown -R applmgr:dba /u02
# chmod -R 775 /u01
# chmod -R 445 /u02

Note: You can omit IDs to set default value for group and user.

Determining if an Oracle Software Owner User Exists:

If the oracle & grid user exists, then the output from this command is similar to the following:

# id oracle
uid=1101(oracle) gid=1000(oinstall) groups=1001(dba)
# id grid
uid=1100(grid) gid=1000(oinstall) groups=1001(dba)

8) Tar and untar in one go:
Basic Tar & untar commands:
-- Tar with .gz
$ export DATE=`date +%Y_%m_%d`
$ tar -czvf Logfile_bkp_$DATE.tar.gz *.log

-- Tar with .tar
$ tar -cvf Logfile_bkp_$DATE.tar  *.LOG


e.g., I want to move entire 'apps' directory from 192.168.1.1 to 192.18.1.2:

$ cd /u02
$ ls
    apps     misc

$ tar zcvf - apps | ssh applmgr@192.168.1.2 '(cd /u03 tar zxvf -)'

Note : This command will tar the 'apps' folder and untar in target machine simuntaniously.


-- To untar / unzip
$ tar -xvf tarfilename.tar
OR
$ tar -xzvf tarfilename.tar.gz

9) AIX – Increase FS size / increase mount size

The following is the procedure which can be used to configure a LUN which is allocated from SAN
and use it to increase the filesystem space .

Please use your own discretion, I will not be held responsible for any issues caused by trying out the commands given below.

This command can be used to increase the filesystem space

chfs -a size=+<space-required>G <mount-point>

eg: This command will add 2G more to the filesystem on the mountpoint

chfs -a size=+2G /mount-point

-- to find all volume groups
# lsvg
rootvg
binaryvg
datavg
bkpvg

-- To find details of one volumen group
-- check if the required space is available

# lsvg <vg-name>
e.g.,

















Example, I am increasing my "/" FS or mount point:

# chfs -a size=+2G /
Filesystem size changed to 8388608

But, When I tried above similar command , I found below error.

# chfs -a size=+30G /oradata
0516-787 extendlv: Maximum allocation for logical volume fslv01
        is 900.

i.e., You need to increase no. of PPS, then increase file system.

see the case study.

# df -g
Filesystem    GB blocks      Free %Used    Iused %Iused Mounted on
/dev/hd4           2.00      1.75   13%    11579     3% /
/dev/hd2           7.00      1.79   75%    54883    12% /usr
/dev/hd9var        2.00      1.38   32%     9208     3% /var
/dev/hd3          10.00      9.70    3%      748     1% /tmp
/dev/hd1          10.00      4.21   58%     7864     1% /home
/dev/hd11admin      0.12      0.12    1%        5     1% /admin
/proc                 -         -    -         -     -  /proc
/dev/hd10opt       0.62      0.01   99%    37137    70% /opt
/dev/livedump      0.25      0.25    1%        4     1% /var/adm/ras/livedump
/dev/lv00          0.06      0.06    4%       18     1% /var/adm/csd
/dev/fslv00       49.00     16.27   67%  1485213    27% /u01
/dev/fslv01      450.00     79.36   83%     6744     1% /oradata
/dev/fslv02      450.00    278.13   39%       81     1% /bkpdata

# lsvg
rootvg
binvg
datavg
bkpvg

-- To see vg details

# lsvg datavg

VOLUME GROUP:       datavg                   VG IDENTIFIER:

00f724a300004c000000014eb099e604
VG STATE:           active                   PP SIZE:        512 megabyte(s)
VG PERMISSION:      read/write               TOTAL PPs:      999 (511488

megabytes)
MAX LVs:            256                      FREE PPs:       98 (50176

megabytes)
LVs:                2                        USED PPs:       901 (461312

megabytes)
OPEN LVs:           2                        QUORUM:         2 (Enabled)
TOTAL PVs:          1                        VG DESCRIPTORS: 2
STALE PVs:          0                        STALE PPs:      0
ACTIVE PVs:         1                        AUTO ON:        yes
MAX PPs per VG:     32512                                  
MAX PPs per PV:     1016                     MAX PVs:        32
LTG size (Dynamic): 256 kilobyte(s)          AUTO SYNC:      no
HOT SPARE:          no                       BB POLICY:      relocatable
PV RESTRICTION:     none                     INFINITE RETRY: no

-- To see MAX LPs allocated

# lslv fslv01
LOGICAL VOLUME:     fslv01                 VOLUME GROUP:   datavg
LV IDENTIFIER:      00f724a300004c000000014eb099e604.2 PERMISSION:  

read/write
VG STATE:           active/complete        LV STATE:       opened/syncd
TYPE:               jfs2                   WRITE VERIFY:   off
MAX LPs:            900                    PP SIZE:        512 megabyte(s)
COPIES:             1                      SCHED POLICY:   parallel
LPs:                900                    PPs:            900
STALE PPs:          0                      BB POLICY:      relocatable
INTER-POLICY:       minimum                RELOCATABLE:    yes
INTRA-POLICY:       middle                 UPPER BOUND:    32
MOUNT POINT:        /oradata               LABEL:          /oradata
MIRROR WRITE CONSISTENCY: on/ACTIVE                            
EACH LP COPY ON A SEPARATE PV ?: yes                                  
Serialize IO ?:     NO                                  
INFINITE RETRY:     no                                  

-- To increse LPs

# chlv -x 990 fslv01   ( added with more 90)


-- To see
# lsvg datavg
VOLUME GROUP:       datavg                   VG IDENTIFIER:

00f724a300004c000000014eb099e604
VG STATE:           active                   PP SIZE:        512 megabyte(s)
VG PERMISSION:      read/write               TOTAL PPs:      999 (511488

megabytes)
MAX LVs:            256                      FREE PPs:       98 (50176

megabytes)
LVs:                2                        USED PPs:       901 (461312

megabytes)
OPEN LVs:           2                        QUORUM:         2 (Enabled)
TOTAL PVs:          1                        VG DESCRIPTORS: 2
STALE PVs:          0                        STALE PPs:      0
ACTIVE PVs:         1                        AUTO ON:        yes
MAX PPs per VG:     32512                                  
MAX PPs per PV:     1016                     MAX PVs:        32
LTG size (Dynamic): 256 kilobyte(s)          AUTO SYNC:      no
HOT SPARE:          no                       BB POLICY:      relocatable
PV RESTRICTION:     none                     INFINITE RETRY: no
# lslv fslv01
LOGICAL VOLUME:     fslv01                 VOLUME GROUP:   datavg
LV IDENTIFIER:      00f724a300004c000000014eb099e604.2 PERMISSION:  

read/write
VG STATE:           active/complete        LV STATE:       opened/syncd
TYPE:               jfs2                   WRITE VERIFY:   off
MAX LPs:            990                    PP SIZE:        512 megabyte(s)
COPIES:             1                      SCHED POLICY:   parallel
LPs:                900                    PPs:            900
STALE PPs:          0                      BB POLICY:      relocatable
INTER-POLICY:       minimum                RELOCATABLE:    yes
INTRA-POLICY:       middle                 UPPER BOUND:    32
MOUNT POINT:        /oradata               LABEL:          /oradata
MIRROR WRITE CONSISTENCY: on/ACTIVE                            
EACH LP COPY ON A SEPARATE PV ?: yes                                  
Serialize IO ?:     NO                                  
INFINITE RETRY:     no


-- Now to increase filesystem

chfs -a size=+30G /oradata

10) Various ways of scheduling Cronjobs in Linux/ AIX servers:

a) cron job every 5 Minutes

*/5 * * * * /home/oracle/scripts/backup.sh

Note: In the same way, use */10 for every 10 minutes, */15 for every 15 minutes, */30 for every 30 minutes, etc.

b) Execute a cron job every 5 Hours

The second field is for hours. If you specify * in this field, it runs every hour. If you specify */5 in the 2nd field, it runs every 5 hours as shown below.

0 */5 * * * /home/scripts/backup.sh

Note: In the same way, use */2 for every 2 hours, */3 for every 3 hours, */4 for every 4 hours, etc.

c) Execute a job every 5 Seconds

Cron job cannot be used to schedule a job in seconds interval. i.e You cannot schedule a cron job to run every 5 seconds. The alternative is to write a shell script that uses ‘sleep 5′ command in it.

Create a shell script every-5-seconds.sh using bash while loop as shown below.

$ cat every-5-seconds.sh

#!/bin/bash
while true
do
 /home/oracle/scripts/backup.sh
 sleep 5
done

Now, execute this shell script in the background using nohup as shown below. This will keep executing the script even after you logout from your session. This will execute your backup.sh shell script every 5 seconds.

$ nohup ./every-5-seconds.sh &

d) Execute a job every 5th weekday

This example is not about scheduling “every 5 days”. But this is for scheduling “every 5th weekday”.

The 5th field is DOW (day of the week). If you specify * in this field, it runs every day. To run every Friday, specify either 5 of Fri in this field.

The following example runs the backup.sh every Friday at midnight.

0 0 * * 5 /home/oracle/scripts/backup.sh
(or)
0 0 * * Fri /home/oracle/scripts/backup.sh
You can either user number or the corresponding three letter acronym for the weekday as shown below.

0=Sun
1=Mon
2=Tue
3=Wed
4=Thu
5=Fri
6=Sat
Note: Get into the habit of using Fri instead of 5. Please note that the number starts with 0 (not with 1), and 0 is for Sun (not Mon).

10) diff command : To compare two files

Ignore white space while comparing.

$ diff sample1.txt sample2.txt

11) sort command examples
Sort a file in ascending order

$ sort sample.txt -- Sort a file in descending order
$ sort -r sample.txt  -- Sort passwd file by 3rd field.
$ sort -t: -k 3n /etc/passwd | more

12) xargs command examples

Copy all images to external hard-drive

# ls *.jpg | xargs -n1 -i cp {} /externaldrive/directory
Search all jpg images in the system and archive it.

# find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz
Download all the URLs mentioned in the url-list.txt file

# cat url-list.txt | xargs wget –c

13) shutdown command examples

Shutdown the system and turn the power off immediately.

# shutdown -h now
Shutdown the system after 10 minutes.

# shutdown -h +10
Reboot the system using shutdown command.

# shutdown -r now
Force the filesystem check during reboot.

# shutdown -Fr now

14) passwd command examples

Change your password from command line using passwd. This will prompt for the old password followed by the new password.

$ passwd
Super user can use passwd command to reset others password. This will not prompt for current password of the user.

# passwd USERNAME
Remove password for a specific user. Root user can disable password for a specific user. Once the password is disabled, the user can login without entering the password.

e,g,
# passwd applmgr

# passwd -d USERNAME

15) uname command examples

Uname command displays important information about the system such as — Kernel name, Host name, Kernel release number,
Processor type, etc.,

Sample uname output from a Ubuntu laptop is shown below.

$ uname -a
Linux eh-uatdb1 2.6.32-279.el6.x86_64 #1 SMP Wed Jun 13 18:24:36 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux

16) OS version & release
a) Linux:
$ cat /etc/redhat-release
Linux eh-uatdb1 2.6.32-279.el6.x86_64 #1 SMP Wed Jun 13 18:24:36 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux

b) AIX:
$ oslevel -s
6100-06-05-1115

17) tail command examples
Print the last 10 lines of a file by default.
$ tail filename.txt
$ tail -n N filename.txt
$ tail -f log-file
Print N number of lines from the file named filename.txt
View the content of the file in real time using tail -f. This is useful to view the log files, that keeps growing. The command can be terminated using CTRL-C.

18) rpm command examples

To install apache using rpm.

# rpm -ivh httpd-2.2.3-22.0.1.el5.i386.rpm
To upgrade apache using rpm.

# rpm -uvh httpd-2.2.3-22.0.1.el5.i386.rpm
To uninstall/remove apache using rpm.

# rpm -ev httpd

19) date command examples

Set the system date:
# date -s "01/31/2010 23:59:53"
Once you’ve changed the system date, you should syncronize the hardware clock with the system date as shown below.

# hwclock –systohc
# hwclock --systohc –utc

Change date with time server / target system

--- hardware clock set
# net time set -S 192.162.1.3
# /sbin/hwclock --systohc

20) Add host name and chage host name without restart server in RHEL

# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain
10.80.37.76 eblr-uatdb-02

# hostname eblr-uatdb-02

21) How Do I Disable Firewall?

First login as the root user.
Next enter the following three commands to disable firewall.
# service iptables save
# service iptables stop
# chkconfig iptables off
e.g.,
#
# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
# service iptables stop
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
# chkconfig iptables off
22) rsync command and some example:

rsync switches
 -a = Archive. Keeps Date Time Permissions etc...
     --archive               archive mode; equals -rlptgoD (no -H,-A,-X)
     --no-OPTION             turn off an implied OPTION (e.g. --no-D)
 -v, --verbose               increase verbosity
 -e = ssh options specify ssh as remote shell
 -h = Output numbers in a human-readable format
 -l = Copy symlinks as symlinks
 -p = Preserve permissions
 -r = Recursive. Gets all sub-directories of specified dirs.
 -z = Compress. Speeds up the transfer by compressing transferred bits.
     --delete = Removes files from target that no longer exist on source system
     --stats = Provides a detailed summary of timings, bits transferred etc..
-u, --update                skip files that are newer on the receiver
     --inplace               update destination files in-place (SEE MAN PAGE)
     --append                append data onto shorter files
     --append-verify         like --append, but with old data in file checksum

Use "rsync --help" to see the options...
-- Example to copy not copied archivelogs from FRA location to target system:

vi ShipArchives.sh

#!/bin/bash
DATE=`date +%d%m%y.%H%M%S`
x="$(ssh oracle@192.160.1.2 date +%d%m%y)"
y=${#x}
if [ $y -eq 6 ]
 then
          rsync -avu --ignore-existing /u03/FRA/archivelog/* oracle@192.160.1.2:/u04/backup/onlinelogs>>/home/oracle/scripts/ShipLogs/Shipped_$DATE.log
 else
           echo "No communication to DESTINATION"
 fi

In crontab:

00,15,30,45 * * * * /home/oracle/scripts/ShipArchives.sh

Another example:

use rsync (& ssh) for EBS cloning the applications filesystems with the following switches.  Its extremely quick for us to copy source to target.

Make sure to copy the correct source directories; ref: Cloning Oracle Applications Release 12 with Rapid Clone [ID 406982.1]

rsync -ahlprz --stats --delete -e ssh $SourceDirectory/. $TargetApplMgr@$TargetServer:$TargetDirectory/

i.e. using ssh to copy from one server to another

23) Few AIX based commands:
a) To Check swap memory:
$ lsps -s
Total Paging Space   Percent Used
      17408MB               0%

b) To check total memory / cores

$ lsconf | grep Memory
Memory Size: 32768 MB
Good Memory Size: 32768 MB
+ mem0                                                                            Memory

$ lsconf | grep CPU
CPU Type: 64-bit

$ lsconf | grep Processor
Processor Type: PowerPC_POWER7
Processor Implementation Mode: POWER 7
Processor Version: PV_7_Compat
Number Of Processors: 3
Processor Clock Speed: 4284 MHz
  Model Implementation: Multiple Processor, PCI bus
+ proc0                                                                           Processor
+ proc4                                                                           Processor
+ proc8                                                                           Processor

c) To determine if the system is started in 64-bit mode, enter the following command:

# bootinfo -K
64

d) To find OS version and TL(Technology Level) level:

# oslevel -s
7100-03-03-1415

e) 3.To determine the supported kernel mode, enter a command similar to the following:

# getconf KERNEL_BITMODE
64

f) Verifying UDP and TCP Kernel Parameters
# /usr/sbin/no -a | fgrep ephemeral
       tcp_ephemeral_high = 65535
        tcp_ephemeral_low = 32768
       udp_ephemeral_high = 65535
        udp_ephemeral_low = 32768

The following recommended values for Oracle 11gR2:

The recommended value for tcp_ephemeral_low is 9000
The recommended value for tcp_ephemeral_high is 65500
The recommended value for udp_ephemral_low is 9000
The recommended value for udp_ephemeral_high is 65500

In the preceding example, the TCP and UDP ephemeral ports are set to the default range (32768-65536).

If you expect your workload to require a high number of ephemeral ports, such as high node counts or heavy use of Parallel Query, then update the UDP and TCP ephemeral port range to a broader range. For 

example:
# /usr/sbin/no -p -o tcp_ephemeral_low=9000 -o tcp_ephemeral_high=65500
# /usr/sbin/no -p -o udp_ephemeral_low=9000 -o udp_ephemeral_high=65500

g) Determining if the Oracle Inventory Group Exists:

If the oraInst.loc file exists, then the output from this command is similar to the following:

# cat /etc/oraInst.loc

inventory_loc=/u01/app/oraInventory
inst_group=oinstall

h) Creating the Oracle Inventory Group 

If the oraInst.loc file does not exist, then create the Oracle Inventory group using the following procedure:

1.Enter the following command:
# smit security
2.Choose the appropriate menu items to create the Oracle Inventory (oinstall) group.

3.Press F10 to exit.

Click here to get more on this 

i) To Find Max parallel servers set in AIX:

# smit chgsys

output:





















j) Checking Asynchronous Input Output Processes

-- In AIX 6.1 & 7.1
# ioo -o aio_maxreqs
aio_maxreqs = 131072

-- In AIX 5.1
lsattr -El aio0 -a maxreqs

When performing an asynchronous I/O to a file system, each asynchronous I/O operation is tied to an asynchronous I/O server. Thus, the number of asynchronous I/O servers limits the number of concurrent asynchronous I/O operations in the system.

k) To verify that the environment has been set correctly, enter the following commands:

$ umask
$ env | more
Verify that the umask command displays a value of 22, 022, or 0022 and that the environment variables you set in this section have the correct values.

l) For IBM AIX on POWER Systems (64-Bit):

Modify /etc/security/limits defaults to read as follows:

fsize = -1
core = 2097151
cpu = -1
data = 1024000
rss = 512000
stack = -1
stack hard = -1
nofiles = 32767
nofiles hard = 327679

Typically, you would have max user processes set to 16384:

#ulimit -u
16384

# ulimit -u
unlimited


To find out the properties of boot log file in AIX

 # alog -L -t boot
/var/adm/ras/bootlog:131072:1

Jan 28, 2015

Configuring mail alerts via PLSQL - Troubleshot ORA-29278

Troubleshot ORA-29278: SMTP transient error: 421 Service not available.

Using utl_smtp:

The obselete utl_smtppackage was first introduced in Oracle 8i to give access to the SMTP protocol from PL/SQL.  The package is dependent on the JServer option  which can be loaded using the Database Configuration Assistant (DBCA) or by running the following scripts as the sys user if it is not already present.

Using the package to send an email requires some knowledge of the SMTP protocol, but for the purpose of this text, a simple send_mail procedure has been written that should be suitable for most error reporting.

Assume: 
>> My SMTP server IP is : 170.1.1.1
>> We will use ALERT user to send test mails.

-- To create alert user:
SQL> create user ALERT identified by xwdkjdlc13ns default tablespace USERS temporary tablespace TEMP profile DEFAULT;
SQL> grant CONNECT to ALERT;
SQL> grant execute on UTL_MAIL to ALERT;
SQL> grant MGMT_USER to ALERT;
SQL> grant SELECT_CATALOG_ROLE to ALERT;

-- Necessary configuration:
-- in spfile set

SQL> alter system set smtp_out_server = '170.1.1.1' scope=spfile;

Now, bounce the database;

-- before set

SQL> show parameter smtp;
NAME                TYPE        VALUE
------------------- ----------- ------------------------------
smtp_out_server     string
SQL>

-- after set
SQL> show parameter smtp;
NAME                TYPE        VALUE
------------------- ----------- ------------------------------
smtp_out_server     string      170.1.1.1
SQL>

-- give grants

SQL> grant execute on UTL_MAIL to public;
OR
SQL> grant execute on UTL_MAIL to ALERT;
SQL> ALTER SESSION SET smtp_out_server = '170.1.1.1';
SQL> exec UTL_MAIL.send(sender => 'oracle.com', recipients => 'gourang_m@gmail.com', subject => 'Test Mail', message => 'Hello World', mime_type => 'text; charset=us-ascii');

If you are facing "ORA-29278: SMTP transient error: 421 Service not available" error, the read the below steps.

The Problem:

You are trying to use the UTL_MAIL package to send email from your database. When attempting to send a mail, you recieve the following error:

SQL> exec utl_mail.send('oracle.com','gourang_m@gmail.com','test mail','Hello World',mime_type => 'text; charset=us-ascii');

ORA-29278: SMTP transient error: 421 Service not available
ORA-06512: at "SYS.UTL_MAIL", line 654
ORA-06512: at "SYS.UTL_MAIL", line 671
ORA-06512: at line 2

Troubleshoot methods:

The Cause:

If this fails it could be a result of many things, so please check all of the items below:

1) SMTP_OUT_SERVER
Check the value for the initialisation parameter SMTP_OUT_SERVER. This should be set to the SMTP server IP. If not, run:

ALTER SYSTEM SET SMTP_OUT_SERVER=”<IP>” scope=both;

2) Recent Upgrade to Oracle 11g
Are you running Oracle database 11g? If so, you will need to have XMLDB & Java installed in order to configure fine grained auditing and enable it there for each user explicitly. You can run through these checks to confirm you have everything in place:

col COMP_NAME format a40;
col VERSION format a12;
col STATUS format a12;
SELECT COMP_NAME, VERSION, STATUS FROM DBA_REGISTRY;

COMP_NAME                                VERSION         STATUS
---------------------------------------- --------------- ---------
Oracle Enterprise Manager                11.2.0.3.0      VALID
Oracle XML Database                      11.2.0.3.0      VALID
Oracle Expression Filter                 11.2.0.3.0      VALID
Oracle Rules Manager                     11.2.0.3.0      VALID
Oracle Workspace Manager                 11.2.0.3.0      VALID
Oracle Database Catalog Views            11.2.0.3.0      VALID
Oracle Database Packages and Types       11.2.0.3.0      VALID
JServer JAVA Virtual Machine             11.2.0.3.0      VALID
Oracle XDK                               11.2.0.3.0      VALID
Oracle Database Java Packages            11.2.0.3.0      VALID

10 rows selected.


If the “JServer JAVA Virtual Machine” and “Oracle XML Database” components are not there then you need to install them to get this working.

The following scripts are what you would use to install Java and XML DB.

Note: These instructions are taken directly from Oracle Metalink, but I would recommend double checking the notes on there just to make sure there have been no updates to them since I wrote this.

3. UTL_MAIL Package & Grants:

You will need to ensure that the UTL_MAIL package exists and that the required users have permission to execute it. You can install it and grant execute privileges on it to a user with the following commands:

SQL/> connect as sysdba
SQL> @?/rdbms/admin/utlmail.sql
SQL> @?/rdbms/admin/prvtmail.plb
SQL> GRANT EXECUTE ON SYS.UTL_MAIL TO USER;

e.g.,
SQL> GRANT EXECUTE ON SYS.UTL_MAIL TO alert;

When executed:

SQL> @?/rdbms/admin/utlmail.sql
Package created.
Synonym created.

SQL> @?/rdbms/admin/prvtmail.plb
Package created.
Package body created.
Grant succeeded.
Package body created.

No errors.
SQL> GRANT EXECUTE ON SYS.UTL_MAIL TO alert;
Grant succeeded.

4. Access Control List (ACL) Configuration:

Have you configured your Access Control List (ACL)? If not, you can do it with the code below. This is required for any Oracle 11g database where you want to send email using Access Control Lists (ACLs) and is a very common error to encounter after upgrading your database from 10g to 11g.

SQL>
BEGIN
  DBMS_NETWORK_ACL_ADMIN.CREATE_ACL (
    acl => 'UTL_SMTP.xml',
    description => 'Granting privs to required users for UTL_SMTP.xml',
    principal => 'ALERT',
    is_grant => TRUE,
    privilege => 'connect');

  DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE (
    acl => 'UTL_SMTP.xml',
    principal => 'ALERT',
    is_grant => TRUE,
    privilege => 'resolve');

  DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL (
    acl => 'UTL_SMTP.xml',
    host => '170.1.1.1');
END;
/

COMMIT;

SQL>
PL/SQL procedure successfully completed

Commit complete
SQL>

Now I am testing the above:

SQL> exec utl_mail.send('oracle.com','gourang_m@gmail.com','test mail','Hello World',mime_type => 'text; charset=us-ascii');

PL/SQL procedure successfully completed
SQL>
Now it is succeeded.

Hopefully that has worked for you, but it may not…You might now be be getting a different error reporting ORA-24247: network access denied by access control list (ACL) if you have not configured your ACLs for the user running the package. if that’s the case, check out that article. It also covers the error whereby you have refreshed your environment from your production environment and receive the ORA-24247: network access denied by access control list (ACL).

Hopefully one of the suggestions above should help you to resolve the issue.

Note:
Limitations on sending e-mail in Oracle with utl_mail. There are several limitations in utl_mail for sending e-mail messages from inside Oracle. The utl_mail package can only handle a RAW datatype, and hence a maximum value of 32k for a 32k mail message.



Translate >>