Thursday, 9 November 2017

Make operating system user non expiry

Many times proper functioning of application demands that the account/password of the OS (Linux/UNIX) user which owns the application should not expire.
chage is the OS command by which we can control the number of days between password changes and the date of the last password change.
The chage command is restricted to the root user, except for the -l option, which may be used by an unprivileged user to determine when the password or account is due to expire.
Let us make password of ‘oracle’ OS user account as non-expiry.

1) CHECK THE CURRENT STATUS OF USER

2) CHANGE AND MAKE IT NON-EXPIRY
# chage -m -1 -M -1 -I -1 -E -1 oracle

Where:
[-m mindays]
[-M maxdays]
[-d lastday]
[-I inactive]
[-E expiredate]
[-W warndays]

3) VERIFY
[root@rclnperp20 ~]# chage -l oracle

UNIX Crontab Basics

A crontab file has five fields for specifying day , date and time followed  by the command to be run at that interval.
#——————————————————————————————
# Minute     Hour    Month Day      Month       Weekday                      Command
#  0-59       0-23      1-31                 1-12           0-6 (0=Sunday)
#——————————————————————————————

* * * * * command to be executed
– – – – –
| | | | |
| | | | +—– day of week (1 – 7) (monday = 1)
| | | +——- month (1 – 12)
| | +——— day of month (1 – 31)
| +———– hour (0 – 23)
+————- min (0 – 59)
crontab -e Edit your crontab file, or create one if it doesn’t already  exist.
crontab -l Display your crontab file.
crontab -r Remove your crontab file.
crontab -v Display the last time you edited your crontab file.


Example:
To run the calendar command at 6:30 a.m. every Monday, Wednesday, and Friday, enter:
To run the calendar command every day of the year at 6:30, enter the following:

To run a script called maintenance every day at midnight in August, enter the following:


You can execute crontab if your name appears in the file /usr/lib/cron/cron.allow. If that file does not exist, you can use  crontab if your name does not appear in the file  /usr/lib/cron/cron.deny.  If only cron.deny exists and is empty, all users can use crontab. If neither  file exists, only the root user can use crontab. The allow/deny files  consist of one user name per line.

Useful UNIX/LINUX commands for DBAs

Below are some of the useful UNIX/LINUX commands which we use frequently:
–LIST YOUR FILES
ls — lists your files
ls -l — lists your files in ‘long format’, which contains lots of useful information, e.g. the  exact size of the file, who owns the file and who has the right to look at it, and when it was last modified.
ls -a — lists all files, including the ones whose filenames begin in a dot, which you do  not always want to see.

–COMPRESSING THE FILE
gzip filename — compresses files, so that they take up much less space. There are other tools for this  purpose, too (e.g. compress), but gzip usually gives the highest compression rate. Gzip produces files with the ending ‘.gz’ appended to the original filename.
gunzip filename — uncompresses files compressed by gzip.


–PRINTING RELATED COMMANDS 
lpr filename — print to default printer
lpr -P<printer_name> filename — Use the -P option to specify the printer name if you want to  use a printer other than your default printer.
lpq — check out the default printer queue.
lpq <printer_name>— check out specific printer queue.
lprm jobnumber — remove specific job queue from the printer queue. Y


–DIRECTORY RELATED COMMANDS
mkdir dirname — make a new directory
cd dirname — change directory.  ‘cd ..‘ will get you one level  up from your current position.
pwd — tells you where you currently are.

–MOVING, RENAMING, AND COPYING FILES
cp file1 file2 —copy a file
mv file1 newname — move or rename a file
rm file1 [file2 ...] —remove or delete a file
rm -r dir1 [dir2...] —recursivly remove a directory and its contents


–VIEWING AND EDITING FILES
cat filename —Dump a file to the screen in ascii.
more filename— Progressively dump a file to the screen: ENTER = one line  down SPACEBAR = page down q=quit
less filename —Like more, but you can use Page-Up too. Not available on all systems.
vi filename —Edit a file using the vi editor. All UNIX systems will have vi in some form.
head filename —Show the first few lines of a file.
head -n filename —Show the first n lines of a file.tail filename —Show the last few lines of a file.
tail -n filename —Show the last n lines of a file


–FIND COMMAND
find search_path -name filename — Find command format
find . -name aaa.txt —Finds all the files named aaa.txt in the current  directory or  any subdirectory tree.
find / -name vimrc —Find all the files named ‘vimrc’ anywhere on the  system.
find /usr/local/games -name “*xpilot*” —Find all files whose names contain the string  ‘xpilot’ which  exist within the ‘/usr/local/games’ directory tree.

–VI EDITOR – VERY IMPORTANT TO LEARN
Start with vi <filename>
Edit modes: These keys enter editing modes and type in the text of your document.
i —Insert before current cursor position
I —Insert at beginning of current line
a —Insert (append) after current cursor position
A —Append to end of line
r —Replace 1 character
R —Replace mode
<ESC> —Terminate insertion or overwrite mode

Deletion of text
x —Delete single character
dd —Delete current line and put in buffer
ndd —Delete n lines (n is a number) and put them in buffer
J —Attaches the next line to the end of the current line (deletes carriage return).

Undo
u —Undo last command

Cut and Paste
yy —Yank current line into buffer
nyy —Yank n lines into buffer
p —Put the contents of the buffer after the current line
P —Put the contents of the buffer before the current line

Cursor Positioning
ctrl-d —Page down
ctrl-u —Page up
:n —Position cursor at line n
:$ —Position cursor at end of file
^g —Display current line number
h,j,k,l —Left,Down,Up, and Right respectivly. Your arrow keys should also work

String Substitution
:n1,n2:s/string1/string2/[g] —Substitute string2 for string1 on lines n1 to n2. If g is included (meaning global),
all instances of string1 on each line are substituted. If g is not included, only the first instance per matching line is substituted.
^ —matches start of line
. —matches any single character
$ —matches end of line
These and other “special characters” (like the forward slash) can be “escaped” with \
i.e to match the string “/usr/STRIM100/SOFT” say “\/usr\/STRIM100\/SOFT”
Examples:
:1,$:s/dog/cat/g —Substitute ‘cat’ for ‘dog’, every instance
for the entire file – lines 1 to $ (end of file)
:23,25:/frog/bird/ —Substitute ‘bird’ for ‘frog’ on lines 23 through 25. Only the first instance on each line is substituted.

Saving and quitting commands
These commands are all prefixed by pressing colon (:) and then entered in the lower left corner of the window.
Press <ESC> to exit from an editing mode.
:w —Write the current file.
:w new.file —Write the file to the name ‘new.file’.
:w! existing.file —Overwrite an existing file with the file currently being edited
:wq —Write the file and quit.
:q —Quit.
:q! —Quit with no changes.
:e filename —Open the file ‘filename’ for editing.
:set number —Turns on line numbering
:set nonumber —Turns off line numbering


–KILLING ALL LOCAL=NO PROCESS BY SINGLE COMMAND  
kill ps -ef | grep <INSTNAME> |grep LOCAL=NO| egrep -v grep | awk '{print $2}'
or
ps -ef| grep -i <INSTNAME> | grep LOCAL=NO| awk {‘print $2′}| xargs kill -9


-CUSTOMIZE UNIX COMMAND PROMPT
Put below value in .profile of user
HOSTNAME=$(uname -n)
PS1='(${?})${LOGNAME}@${HOSTNAME}:${ORACLE_SID:-“NO_SID”}: ${PWD}
$ ‘
PS2=’> ‘


–MOUNT COMMAND
mount -t nfs -o <options> server-name-or-ip-address:/<file_system_to_mount> /<file_system_to_mount>

–To find the number of physical CPUs:
$ cat /proc/cpuinfo | grep "^physical id" | sort | uniq | wc -l
 2

–To find the number of cores per CPU:
$ cat /proc/cpuinfo | grep "^cpu cores" | uniq
cpu cores : 4
The total number of processors available is the number of physical CPUs multiplied by the number of cores per CPU.

–To find the total number of processors:
$ cat /proc/cpuinfo | grep "^processor" | wc -l
 16

Important Solaris Commands

Solaris is one of the flavor of UNIX and is currently controlled by Oracle corporation.
Below are some of the useful Soalris command from DBA  perspectives.
 MEMORYprtconf | grep Memory
prtconf: devinfo facility not available
Memory size: 261632 Megabytesprtdiag | grep Memory
 DISK$ iostat -xzn 5
extended device statistics
r/s    w/s   kr/s   kw/s wait actv wsvc_t asvc_t  %w  %b device
8.2    6.2  163.8   90.0  0.5  0.2   35.4   13.1   8  10 c3d0
1.4   12.2   30.0   81.4  0.1  0.2    8.9   13.0   3   7 c6t0d0
Look at the wait: This is the number of IO operations that are waiting to be serviced. In other words: “wait” tells you the waiting queue length. If the wait time is in the single digit range, then your problem may be elsewhere.
$ fsstat -F 5 new  name   name  attr  attr lookup rddir  read read  write write file remov  chng   get   set    ops   ops   ops bytes   ops bytes 0     0     0     0     0      0     0     0     0     0     0 ufsv 0     0     0 1.05K     0  2.22K     4 1.04K  406K     2    32 proc 0     0     0     0     0      0     0     0     0     0     0 nfs 1     1     0 3.89K     5  12.6K     4  9.7K 1.33M 8.19K  568K zfs 0     0     0    41     0      0     0     0     0     0     0 lofs 8     0     6    33     0     34     0     2     0     6 2.41K tmpfs 0     0     0     0     0      0     0     0     0     0     0 mntfs 0     0     0     0     0      0     0     0     0     0     0 nfs3 0     0     0     0     0      0     0     0     0     0     0 nfs4

Are your users creating lots of files? Or are they modifying/removing/changing attributes a lot? What filesystems are causing the most IO load? How much IO goes through NFS and how much is local? All these questions can be easily answered with fsstat and a few flags.
 CORESTotal number of cores in a system is
$ kstat cpu_info | grep core_id | uniq | wc -l
32
Divide the total number of cores by the output of “psrinfo -p” to get the cores per physical processor
$ psrinfo -p
4
So 32/4 = 8 cores per physical processor
$ psrinfo -pv
The physical processor has 64 virtual processors (0-63)
  SPARC-T4 (chipid 0, clock 2848 MHz)
shows physical and virtual processor (CPU).
 PRSTAT (TOP like command)prstat -a
prstat -a -s size (MEMORY CONSUMING PROCESS IN DESCENDING ORDER)
ps -efo pmem,rss,pid,pcpu,args | sort -r | head -20
prstat -t  (It provides complete users resource utilization)
prstat -L (This shows thread per line instead of one process per line)
PID:
the process ID of the process.
USERNAME:
the real user (login) name or real user ID.
SIZE:
the total virtual memory size of the process, including all mapped files and devices, in kilobytes (K), megabytes (M), or gigabytes (G).
RSS:
the resident set size of the process (RSS), in kilobytes (K), megabytes (M), or gigabytes (G).
STATE:
the state of the process (cpuN/sleep/wait/run/zombie/stop).
PRI:
the priority of the process. Larger numbers mean higher priority.
NICE:
nice value used in priority computation. Only processes in certain scheduling classes have a nice value.
TIME:
the cumulative execution time for the process.
CPU:
The percentage of recent CPU time used by the process. If executing in a non-global zone and the pools facility is active, the percentage will be that of the processors in the processor set in use by the pool to which the zone is bound.
PROCESS:
the name of the process (name of executed file).
NLWP:
the number of lwps in the process.
—————————–
load average: 0.65 0.42 0.36
0.65 is the average over the last minute, 0.42 is the average over the last five minutes, and 0.36 is the average over the last 15 minutes.
 PRSTAT (Sort the TOP Like command)prstat -s
prstat ouput can be sorted using set of sub-options .sub options are cpu,pri,rss,size,time
(Ex:prstat -s cpu)
cpu – sort by process cpu usage on the system
pri – sort the process by priority
rss – sort by resident set size (i.e physical memory)
size – sort by size of the process (i.e virtual memory)
time – sort by process execution time
 Prstat -mlprstat -mL
This command is very useful to find out where is the actual issue on the system.The blow output shows the percentage of time spent in a given microstate over the last sampling period (default is 5 seconds), beginning with the USR column, up to and including the LAT column. The values in the columns USR through LAT should total 100, accounting for 100% of the threads time for the last sampling period.
# prstat -mL
System Bottleneck determination using prstat -mL
Description        Fields
Other users and application (Like top command usr field)                                     USR
Kernel (Like top command sys fields)                                                       SYS
Monitor the amount of time threads wait for a processor (CPU bottleneck identification)  LAT
Memory paging waits (Memory bottleneck identification)                                     TFL and DTL
Disk and Network waits (I/O bottlenect identification )                                     SLP
 PRSTAT Continuous modeprstat -c
prstat -c -n 3  (it will print only top 3 rows)
With the option -c to prstat, new reports are printed below previous ones, instead of overprinting them. This is especially useful when gathering information to a file (i.e. prstat -c 2 > prstat.txt). The option -n <number of output lines> can be used to set the maximum length of a report.
 Total number of physical processors psrinfo -p
 Total number of physical and virtual processors psrinfo -pv
 Total number of virtual servers psrinfo -v
 Kill all specific  processes example apache for specific user oaoracle ps -fu oaoracle|grep apache| grep -v grep | awk ‘{print $2}’ | xargs kill -9
 VMSTAT (Virtual Memory Statistics)Vmstat
Or
vmstat 5 (Collect virtual memory statistics with a time interval in 5 seconds)
procsReports on the following:
rThe number of kernel threads in the dispatch queue
bThe number of blocked kernel threads that are waiting for resources
wThe number of swapped out LWPs that are waiting for processing resources to finish
memoryReports on usage of real memory and virtual memory:
swapAvailable swap space
freeSize of the free list
pageReports on page faults and paging activity, in units per second:
rePages reclaimed
mfMinor faults and major faults
piKbytes paged in
poKbytes paged out
frKbytes freed
deAnticipated memory that is needed by recently swapped-in processes
srPages scanned by the page daemon not currently in use. If sr does not equal zero, the page daemon has been running.
diskReports the number of disk operations per second, showing data on up to four disks
faultsReports the trap/interrupt rates per second:
inInterrupts per second
sySystem calls per second
csCPU context switch rate
cpuReports on the use of CPU time:
usUser time
sySystem time
idIdle time

EXAMPLE
$ vmstat 5
kthr      memory            page            disk          faults      cpu
r b w   swap  free  re  mf pi po fr de sr cd s0 s2 —   in   sy   cs us sy id
0 0 0 446144 130076 23 100  0  1  3  0 12  7 -0 13  0  465 1352 1137  6 12 82
0 0 0 405376 90808  33  41  0  0  0  0  0 39  0  3  0  514  500  571  4 11 85
0 0 0 405296 90536   0   0  0  0  0  0  0 29  0  1  0  502  778  551  4 10 86
(Remember to ignore the first line of the output as it may contain accumulated data from an unknown sample size.)
FOR CPU
Now watch the rightmost column, which is the system idle time in percent. Is it bigger than 0 most of the time? Then you have enough CPU power. It’s that simple. If idle time is 0 most of the time, buy a bigger CPU, if not, look elsewhere.
FOR MEMORY
Look at three values: swap, free and sr (or: scan rate):
swap: This is the amount of free virtual memory.
free: This is the amount of free physical memory.
scan rate (sr): This is the number of times that the memory page scanner is cleaning up memory pages, freeing the lesser used memory pages to make room for data that needs to be allocated from physical memory. The bigger this value, the more stressed our memory subsystem is, because the OS is more and more busy scanning memory pages for expendable chunks so it can fulfill a high demand in fresh memory. If the scan rate is a single digit value most of the time, you’re ok. If it shows large values over extended periods of time, you’ll likely benefit from some extra RAM in your system.
 Find process information pfiles <process_id>
 Disk Type iostat -E
 Change the prompt in SoalrisPS1=”`hostname`:`pwd` >”
 or
 ksh
PS1=’$PWD>’; export PS1
 System and Software Version showrev -a
 System Product Name prtconf -b

Sunday, 23 October 2016

Unable to send mails from Linux servers

Here are the steps to configure sendmail ..  In case if you notice the setup is missing on any of the servers..
keep these commands handy..

1.       Backup sendmail.mc
cp -p /etc/mail/sendmail.mc /etc/mail/sendmail.mc_orig
2.    Modify the external smtp server (uncommenting the line and updating the value )
dnl define(`SMART_HOST', `smtp.your.provider')dnl
to
define(`SMART_HOST', `mail.global.frontbridge.com')dnl

3.    Compile
make all

4.    Restart sendmail service
(OEL - 7)
systemctl start sendmail
systemctl enable sendmail

Lower versions
/etc/init.d/sendmail restart
(or)
/etc/init.d/sendmail start

Sunday, 9 October 2016

VirtualBOX error /tmp/vbox.0/Makefile.include.header:97: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=

During the installation of “Insert Guest Additions CD Image” everytime it was failing.  The purpose of installing is will help us in free movement of cursor(mouse pointer) from host to guest and vice versa without using right CTRL key. Everytime if we want to move our cursor from guest to host or host to guest we need to press right CTRL key.
I am running my host on Windows7
and Guest running on OEL6.4
When i was installing i see below error:
vbox
When i checked the log file mention in the above screen, i see below error.
Creating udev rule for the Guest Additions kernel module.
/tmp/vbox.0/Makefile.include.header:97: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again. Stop.
Creating user for the Guest Additions.
To overcome this error update gcc using
1.yum update gcc
2. yum update
3. yum install kernel-uek-devel
*Please note that to execute “yum” your guest vmbox should have internet connection
now after doing all the above I again executed ./VMBoxLinuxAdditions.run
successYes I am able to successfully finish the Insert VMBox Guest Addition CD Image on Virtual Guest

Step By Step OEL 6.4 Install

In this post i will list out all the steps to Install OEL 6.4.
Download the software from edelivery.oracle.com
1a
1
Select Install or Upgrade the existing System23
Select Skip4567
8
9
10
11
12
1314
1516
1718
19
202122 24
252627282930313233
Login with root. Once login disable the firewall.
34