Thursday, January 1, 2015

Linux Commands for Oracle DBAs

Firstly, I would like to wish you all a very Happy New Year 2015.

This article has the list of useful Linux commands/tasks that an Oracle DBA should know,

1. Samba mount from linux to windows
2. Changing color coding in linux TTY
3. 'vncserver' command
4. Printer commands
5. 'rlwrap' readline wrapper for Command Line History and Editing in SQLPLUS and RMAN on Linux
6. winscp Script to copy files from Linux to Windows
7. How to unmount when the device is busy
8. Edit the sudoer file using visudo
9. 'chkconfig' command to make services automatically starts when server is restarted
10. 'chage' command to change user password expiry information
11. 'find' command
12. Few vi Editor shortcuts
13. Commands to monitor
14. Compare installed rpms on two servers
15. Configure Yum Repository
16. Kill processes with one command
17. tar Command
18. Sendmail configuration
19. touch command
20. Miscellaneous Commands

1. Samba mount from Linux to Windows

Samba mount from Linux to Windows i.e., you will see the shared folder on windows machine but acutally folder is on the Linux server.


[root@edolraclin1 ~]# cd /u01
[root@edolraclin1 /u01]# mkdir mydir {creating the directory mydir so as to share it to windows machine}

[root@edolraclin1 /u01]# chmod -R 777 mydir
[root@edolraclin1 /u01]# chown -R oracle:oinstall /u01/mydir



Add the below section in smb.conf file,



[root@edolraclin1 ~]# vi /etc/samba/smb.conf

[mydir]
comment = mydir directory mounted on windows server edwinsrv1
path = /u01/mydir
available = yes
valid users = oracle
readonly = no
browsable = yes
public = yes
writable = yes

[root@edolraclin1 ~]# service smb restart {Restart the smb service to take affect the above settings}

[root@edolraclin1 ~]# smbpasswd -a oracle  {this will change oracle user's SMB password}

Use map network drive and select the linux server name edolraclin1 and you will see the shared folder 'mydir' and you can map it on the windows machine edwinsrv1 and start using it. For username/password enter the username of linux os {oracle/password}.

2. Changing color coding in linux TTY


 
[root@edolraclin1 ~]# echo $COLORS
/etc/DIR_COLORS.xterm


To see all the file types and its text color codes and Background color codes you can read /etc/DIR_COLORS.xterm file,



To customized colors you must use special string combination as below:

FILE-TYPE Text color codes;Background color codes

Where,

FILE-TYPE: is file type like DIR (for directories)
Attribute codes:
00=none
01=bold
04=underscore
05=blink
07=reverse
08=concealed
Text color codes:
30=black
31=red
32=green
33=yellow
34=blue
35=magenta
36=cyan
37=white
Background color codes:
40=black
41=red
42=green
43=yellow
44=blue
45=magenta
46=cyan
47=white

For example to define Bold Blue color for DIR file type, entry should look as follows:

[root@edolraclin1 ~]# vi /etc/DIR_COLORS.xterm
DIR 01;34

Logout and login again, Please note that if you have shell variable defined COLORS then use that file (use echo $COLORS to find it out).

3. VNC
vncserver is used to start a VNC (Virtual Network Computing) desktop.  vncserver is a Perl script which  simplifies the process of starting an Xvnc server.

vncserver can be run with no options at all. In this case it will choose the first available display  number  (usually :1), start Xvnc as that display, and run a couple of basic applications to get you started.

You can also specify the display number, in which case it will use that number if it is available and exit if not,

eg: vncserver :3

Editing the file $HOME/.vnc/xstartup allows you to change the applications run at startup (but note that this will not affect an existing desktop).

To start the VNCSERVER just type vncserver and enter,

[root@edolraclin ~]# vncserver

You will require a password to access your desktops.

Password:******
Verify:******
xauth:  creating new authority file /root/.Xauthority
xauth: (stdin):1:  bad display name "edolraclin:1" in "add" command

New 'edolraclin:1 (root)' desktop is edolraclin:1

Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/edolraclin:1.log

To Kill a running vncserver you can use the below command,


[root@edolraclin ~]# vncserver -kill :1

4. Printer commands

Install the below rpms to configure the CUPS (Common Unix Printing System) on Linux server,

libgnomecups-0.2.2-9
libgnomecups-0.2.2-9
cups-libs-1.3.7-26.el5_6.1
cups-1.3.7-26.el5_6.1
hal-cups-utils-0.6.2-5.2.el5
bluez-utils-cups-3.7-2.2
cups-libs-1.3.7-26.el5_6.1

To start the CUPS service use the below commands,


[root@edolraclin ~]# service cups restart



[root@edolraclin ~]# /etc/init.d/cups restart



[root@edolraclin ~]# more /etc/printcap {This file will automatically gets genearted by cupsd daemon}



[root@edolraclin ~]# ps -ef | grep cupsd {To check process number for cupsd daemon}
 
[root@edolraclin ~]# system-config-printer

[root@edolraclin ~]# gnome-open http://localhost:631

Below command shows all the added printers and their statuses.
[root@edolraclin ~]# /usr/bin/lpstat -a  

[root@edolraclin ~]# /usr/sbin/lpinfo
[root@edolraclin ~]# /usr/sbin/lpadmin

For canon printers I usually use the below to access the printer configuraiton page,
lpd://ipaddress:515 

While for xerox type printers use the below,
http://ipaddress:631/ipp

[root@edolraclin ~]# xpadmin {To open xerox printer admin tool}
Few more commands,
[root@edolraclin ~]# ps -ef | grep lp
[root@edolraclin ~]# lpstat -a
[root@edolraclin ~]# lpstat -p
[root@edolraclin ~]# lpstat -o {To check what is printing now}
[root@edolraclin ~]# cancel <job name> {To cancel specific job that we see in output of 'lpstat -o'}

[root@edolraclin ~]# enable myxeroxHOPrinter00 {To enable a printer}
[root@edolraclin ~]# disable myxeroxXYZPrinter01 {To disable a printer}

5. rlwrap for Command Line History and Editing in SQL*Plus and RMAN on Linux

The rlwrap (readline wrapper) utility provides a command history and editing of keyboard input for any other command. This is a really handy addition to SQL*Plus and RMAN on Linux.



[root@edolraclin ~]# su -

[root@edolraclin ~]# cd /tmp/rlwrap-0.37

[root@edolraclin ~]# ./configure

[root@edolraclin ~]# make

[root@edolraclin ~]# make check

[root@edolraclin ~]# make install

Now create the below alias in the ".bash_profile" of the oracle software owner.

alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'

Now use sqlplus from command prompt and it will use rlwrap utility,
[root@edolraclin ~]# sqlplus / as sysdba
SQL> select sysdate from dual;

Now up/down arrow keys will work to see the command history and for editing of keyboard input for any other command.


6. Use winscp Script to copy files from Linux to Windows

Install the WINSCP.exe on windows server. Then use the below command to copy the file from linux machine edolraclin to local windows D-Drive.
On the windows command prompt run the below,
c:\> "C:\Program Files (x86)\WinSCP\WinSCP.com" linuxusername:password123@edolraclin -hostkey="ssh-rsa 2048 12:34:ab:c6:d1:e5:fg:78:39:a5:95:cd:75:1f:aa:30"
/log=D:\get_file_from_edolraclin1.log /command "option batch on" "option confirm off" "get /u01/oracle/TEST01.txt D:\TEST01.txt "exit"


In the above to get the server's fingerprints use the below command,
[root@edolraclin ssh]# ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub 2048 12:34:ab:c6:d1:e5:fg:78:39:a5:95:cd:75:1f:aa:30 /etc/ssh/ssh_host_rsa_key.pub

-l display output
-f input_keyfile

[root@edolraclin ssh]# cd /home/root/.ssh/
[root@edolraclin ssh]# more known_hosts

7. How to unmount when the device is busy



When trying to unmount a file system you may got the typical error like,



[root@edolraclin1 ~]# umount /u03

umount: /u03: device is busy

umount: /u03: device is busy



A good chance to see why you can't unmount a file system is using 'fuser' command,


[root@edolraclin1 ~]# fuser /u03
/u03:                52153 52166121414c

With the -u option followed by the unmountable file system fuser will show the user who is currently using the file system. To see what the user is doing run ps and grep for the PID the fuser shows you,

# ps -ef | grep 52153
root 52153 50012   0 10:45:00 pts/1       0:00 -ksh

[root@edolraclin1 ~]# fuser -u /u03
/u03:                52153(root) 52166(root)121414c(root)

[root@edolraclin1 ~]# fuser -k /u03
Cannot stat file /proc/7407/fd/32: No such file or directory
/u03:                52153 52166121414c



[root@edolraclin1 ~]# kill -9 52153

/u03 should be unmountable again. Another option to kill all processes that are using a file system is -ck option for fuser:

[root@edolraclin1 ~]# fuser -ck /u03
/u03:    52153c

This will kill all processes that are using the /mnt mountpoint immediatly. After that the file system is unmountable again:

[root@edolraclin1 ~]# umount /u03
  
Still if the unmount doesn't happen then do lazy umount which immediately detaches the drive from the filesystem, and then cleans up the mess afterwards. This is especially handy if it’s a networked file system (NFS etc) and the network has gone down. Following -l option is for a lazy unmount,

[root@edolraclin1 u03]# umount -l /u03

 
8. Edit the sudoer file using visudo

[root@edolraclin1 ~]# visudo

Add the below lines to allow user to run only the below commands with sudo option.

sami ALL=/etc/init.d/cups restart,/bin/rpm
appldev ALL=/bin/mount

[root@edolraclin1 ~] su - sami
[sami@edolraclin1 ~] sudo /etc/init.d/cups restart


 
9. chkconfig command to make services automatically starts when server is restarted


The below command will list all the services that are configured in the server,



[root@edolraclin1 ~]# chkconfig --list



To check specific service like NFS if it will automatically start or not when the server is restarted, use the below command,



[root@edolraclin1 ~]# chkconfig --list nfs



nfs             0:off   1:off   2:off    3:off   4:off    5:off    6:off


If for run level 3, 4,5 the value is off then make it 'on' by the below command

[root@edolraclin1 ~]# chkconfig nfs on
[root@edolraclin1 ~]# chkconfig --list nfs

nfs             0:off   1:off   2:on    3:on    4:on    5:on    6:off

Now you can reboot the machine and check the nfs status and it will be automatically started.

[root@edolraclin1 ~]# reboot
[root@edolraclin1 ~]# service nfs status
nfsd (pid 6641 6640 6639 6638 6637 6636 6635 6634) is running...
rpc.rquotad (pid 6550) is running...
 
10. 'chage' command to change user password expiry information

To list current aging type chage command as follows:



[root@edolraclin1 ~]# chage -l oracle


Last password change                                    : Jan 01, 2015

Password expires                                          : never

Password inactive                                          : never

Account expires                                             : never

Minimum number of days between password change          : 0
Maximum number of days between password change         : 99999
Number of days of warning before password expires            : 7
 
To disable password aging/expiration for a user, type command as follows and set the password aging policy,

It is an Interactive mode command,

[root@edolraclin1 ~]# chage oracle


11. 'find' command


Files can be found under Linux in many different ways. Using the find tool is one of the best ways to find files. The find tool has a huge number of parameters which can be set so that Linux finds exactly those files that you were searching for. Many users use the find tool with just the basic parameters. They get the results that they were looking for. Unfortunately most of the users don't spend time to learn all about find. If they do, they can make excellent use of this tool and I am sure you would be surprised at the possibilities.



In case you just want to know where a particular file exists on your system, and nothing else is required, then use locate tool.



Here are a few ways to use find,



a.) Search for a string in all *.sh Files



[root@edolraclin1 ~]# egrep -i "search_string_here" *.sh --color

b.) Search for Files that are modified in last 30 days
[root@edolraclin1 ~]# find . -name "*.*" -mtime -30 > /tmp/test.txt




c.) Find a file in / and its sub-directory
[root@edolraclin1 ~]# find / -name 'NetBackup' 2>/dev/null
[root@edolraclin1 ~]# find / -iname 'NetBackup' 2>errors.txt

Here -name means case sensitive name
-iname means non case sensitive search,
/ Starts searching from the root directory (i.e / directory),
-name Given search for filename rather than any other attribute of a file,
Always enclose the filename in single quotes,

2>/dev/null is not related to find tool as such. 2 indicates the error stream in Linux, and /dev/null is the device where anything you send simply disappears,
So 2>/dev/null in this case means that while finding for the files, in case any error messages pop up simply send them to /dev/null i.e. simply discard all error messages.


Alternatively you could use 2>error.txt where after the search is completed you would have a file named error.txt in the current directory with all the error messages in it.



[root@edolraclin1 ~]find /home/sami -name 'index*'
[root@edolraclin1 ~]# find /home/sami -iname 'index*'

The 1st command would find files having the letters index as the beginning of the file name. The search would be started in the directory /home/sami and carry on within that directory and its subdirectories only.
The 2nd command would search for the same, but the case of the filename wouldn't be considered. So all files starting with any combination of letters in upper and lower case such as INDEX or indEX or index would be returned.



[root@edolraclin1 ~]find -name met*
The above command would start searching for the files that begin with the letters 'met' within the current directory and the directories that are present within the current directory. Since the directory is not specified as the the second parameter, Linux defaults to using the current directory as the one to start the search in.

d.) find a file with specific size

[root@edolraclin1 ~]find /mp3collection -name '*.mp3' -size -5000k
[root@edolraclin1 ~]find / -size +10000k
The 1st command would find within a directory called /mp3collection, only those mp3 files that have a size less than 5000 Kilobytes ( < 5MB)
The 2nd command would search from the / directory for any file that is larger than 10000k (> 10MB)

e.) Find files accessed in last few minutes

[root@edolraclin1 ~]find /home/sami -amin -10 -name '*.c'
[root@edolraclin1 ~]find /home/sami -atime -2 -name '*.c'
[root@edolraclin1 ~]find /home/sami -mmin -10 -name '*.c'
[root@edolraclin1 ~]# find /home/sami -mtime -2 -name '*.c'

In the above, The 1st commmand searches for those files that are present in the directory /home/sami and its subdirectoires which end in .c and which have been accessed in the last 10 minutes.
The 2nd command does the same but searches for those files that have been accessed in the last 10 hours.
The 3rd and the 4th commands do the same as the 1st and 2nd commands but they search for modified files rather than accessed files. Only if the contents of the files have been modified, would their names be returned in the search results.

f.) Find with AND, OR, NOT Boolean operators



[root@edolraclin1 ~]#  find /mp3-collection -name 'Baazigar*' -and -size +10000k
[root@edolraclin1 ~]#  find /mp3-collection -size +10000k ! -name "Baazigar*"
[root@edolraclin1 ~]#  find /mp3-collection -name 'Baazigar*' -or -size +10000k

Boolean operators such as AND, OR and NOT make find an extremely useful tool.
The 1st command searches within the directory /mp3-collection for files that have their names beginning with 'Baazigar' and whose size is greater than 10000 kilobytes (> 10 MB).
The 2nd command searches in the same directory as above case but only for files that are greater than 10MB, but they should not have 'Baazigar' as the starting of their filenames.
The 3rd command searches in the same directory for files that begin with 'Baazigar' in their names or all the files that are greater than 10 MB in size.

g.) Find with exec execute option

The exec option is probably the most important feature of the find tool. The exec command allows you to execute a particular command on the results of the find command. A simple demonstration of this feature is shown below. Its upto your imagination to make maximum use of this feature. Suppose you wanted to see the details of the files (read, write, execute permission, file size, owner etc..) that have been returned as a search result you could do the following

[root@edolraclin1 ~]# find / - name 'Baazigar*' -exec ls -l {\}\ \;

This command would find all the files on your system that begin with the letters 'Baazigar' and would then execute the 'ls -l' command on these files. So basically you would be able to see the details of the files that were returned according to your search criteria.

The words following the -exec option is the command that you want to execute i.e. ls -l in this case.
{\}\ is basically an indicator that the filenames returned by the search should be substituted here.
\; is the terminating string, and is required at the end of the command.

h.) Search for some text string in a file in current directory .

[root@edolraclin1 ~]#  grep -H -r "Error 500" .

[root@edolraclin1 ~]#  grep -H -r -i "Error 500" .

[root@edolraclin1 ~]# egrep -i "ORA-|Warning|Fatal|failed|invalid" /u01/apps/oracle/admin/log/adpatch.lgi

-H is to only display file name 
-r is to search recursively in subdirectories, -i ignore case


12. Few vi VIM Editor shortcuts
a.) Substitute all occurrences of a text with another text in the whole file
This is the basic fundamental usage of the text substitution inside Vi editor. When you want a specific text to be replaced with another text in the entire file then you can use the following sequence.

:%s/old-text/new-text/g

%s – specifies all lines. Specifying the range as ‘%’ means do substitution in the entire file.
g – specifies all occurrences in the line. With the ‘g’ flag , you can make the whole line to be substituted. If this ‘g’ flag is not used then only first occurrence in the line only will be substituted.

b.) Substitution of a text with another text only the 1st X number of lines
Using count in substitution, If you specify the count N in the substitution then it means do substitution in N lines from the current position of the cursor. do substitution in 4 lines from the current line.

:s/helo/hello/g 4


13. Commands to monitor

a.) sosreport - generates  a compressed tarball of debugging information for the system it is run on that can be sent to technical support reps that will give them a more complete view of the overall system status.

# sosreport


sosreport (version 1.7)
This utility will collect some detailed  information about the hardware and  setup of your  Oracle Linux  system.
The information is collected and an archive is  packaged under /tmp, which you can send to a support representative.
This information will be used for diagnostic purposes ONLY and it will be considered confidential information.
This process may take a while to complete. No changes will be made to your system.
Press ENTER to continue, or CTRL-C to quit.

b.) iostatReport Central Processing Unit (CPU) statistics and input/output statistics for devices and partitions.


# iostat 2 5 {generates the below iostat 5 times every 2 seconds}


avg-cpu:  %user   %nice %system %iowait  %steal   %idle

                 0.00    0.00    0.00    0.04    0.00   99.96





Device:          tps    Blk_read/s   Blk_wrtn/s   Blk_read  Blk_wrtn

sda               1.00         0.00        35.82          0           72

sda1              0.00         0.00         0.00          0           0

sda2              1.00         0.00        35.82          0          72
dm-0              4.48         0.00        35.82          0          72
dm-1              0.00         0.00         0.00          0           0
 
c.) mpstat - command writes to standard output activities for each available processor, processor 0 being the first one. Global average activities  among  all processors are also reported.  The mpstat command can be used both on SMP and UP machines, but in  the  latter,  only  global average activities will be printed. 

# mpstat 2 5 {generates the below mpstat 5 times every 2 seconds}

Linux 2.6.18-274.el5 (edolraclin1)        01/01/2015
12:34:23 PM  CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
12:34:23 PM  all       0.00      0.00      0.00    0.01        0.00    0.00    0.00      99.99   1020.87
d.) vmstat - reports information about processes, memory, paging, block IO, traps, and cpu activity. The first report produced gives averages since the last reboot.  Additional reports give information on a sampling period of length delay. The process and memory reports are instantaneous in either case.
delay is the delay between updates in seconds.  If no delay is specified, only one report is printed with the average values since boot.

# vmstat 2 5 {generates the below vmstat 5 times every 2 second}

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 14713548 285392 811484    0    0     0     0    0    1  0  0 100  0  0
e.) sar - Collect, report, or save system activity information.

# sar

                       CPU     %user     %nice   %system   %iowait    %steal     %idle
10:20:01 AM       all      0.00      0.00      0.00      0.00      0.00     99.99
10:30:01 AM       all      0.00      0.00      0.00      0.01      0.00     99.98
10:40:01 AM       all      0.00      0.00      0.00      0.01      0.00     99.99
f.) top -  The top program provides a dynamic real-time view of a running system.  It can display system summary information as well as a list of tasks currently being managed by the Linux kernel.

# top

use
'h' for help
'O' for sorting
'f' is to select the columns to display


PID    USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
15967 root      15   0 13024 1388  828 R  0.7  0.0   0:00.12 top
    1    root      15   0 10368  676  564 S  0.0  0.0   0:03.56 init
    2    root      RT  -5     0    0    0 S  0.0  0.0   0:00.02 migration/0
g.) iotop

# iotop

h.) strace - trace system calls and signals.  In the simplest case strace runs the specified command until it exits.  It intercepts and records the system calls which are called by a process and the signals which are received by a process.  The name of each system call, its arguments and its return value are printed on standard error or to the file specified with the -o option.

i.) netstat - Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships

# netstat -nap | grep 7031

# netstat -r {Gives route information as below}

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
10.223.222.0    *               255.255.255.0   U         0 0          0 eth0
192.168.0.10   *               255.255.255.0   U         0 0          0 virbr0
default         10.223.222.110  0.0.0.0         UG        0 0          0 eth0
j.) tcpdump - dump traffic on a network. prints  out the headers of packets on a network interface that match the boolean expression.  It can also be run with the -w flag, which causes it to save the packet data to a file for later analysis, and/or with the -r flag, which causes it to read from a saved packet file rather than to read packets from a network interface.  In all cases, only packets that match expression will  be  processed  by tcpdump.
# tcpdump -D

1.eth0
2.virbr0
3.eth1
4.eth3
5.__tmp622860243
6.any (Pseudo-device that captures on all interfaces)
7.lo
# tcpdump -i eth0

# tcpdump -i 1 -c2 {to capture 2 packets}

k.) oswbb - oswatcher black box. This should be installed and will generated grapihical pictures.


l.) dmesg - for hardware errors. dmesg is used to examine or control the kernel ring buffer. The program helps users to print out their bootup messages. Print or control the kernel ring buffer





14. Compare installed rpms on two servers

Compare the difference of RPMs installed on Server1 & Server2 can be found using the below commands,



# rpm -qa | wc -l {count number of rpms}

# ls -l /oel5_repo | wc -l {count number of files in a folder}

# rpm -qa | sort {sorts the output}

 
# rpm -qa --queryformat='%{NAME}\n' | sort > server.txt

# for p in $(cat rpms_server1.txt) ; do grep $p rpms_server2.txt >/dev/null || echo $p ; done

# for p in $(cat rpms_server1.txt) ; do grep $p rpms_server2.txt >/dev/null || echo $p ; done > finalMissingRPMsOnServer2.txt

15. Configure Yum Repository

Create a (local) repository and use yum to have it resolve the dependencies for you.

Create a directory for local repository, e.g. /root/Server.

Move the RPMs into that directory.

Fix some ownership and filesystem permissions:

# chown -R root:root /root/Server

Install the createrepo package if not installed yet, and run

# cd /root/Server
# createrepo /root/Server
# chmod -R 777 /root/Server

Create a repository configuration file, e.g. /etc/yum.repos.d/myrepo.repo containing

# cd /etc/yum.repos.d/
# vi myrepo.repo

[local]
name=My Repository
baseurl=file:///root/Server
enabled=1
gpgcheck=0

Now you can Install your package using,

# yum install packagename


A simpler solution. If you have all the RPMs in the same directory, all you need to do is,

# rpm -i *.rpm
rpm seems to figure out the correct order to install these and installs the RPMs.

That still not handle the case if the dependencies are not in current directory.

       rpm {-i|--install} [install-options] PACKAGE_FILE
       rpm {-U|--upgrade} [install-options] PACKAGE_FILE
       rpm {-F|--freshen} [install-options] PACKAGE_FILE
       rpm {-e|--erase} [--allmatches] [--nodeps] [--noscripts]


While installing through yum if we get below error then use --nogpgcheck option

warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Public key for bsf-2.3.0-11jpp.1.x86_64.rpm is not installed

yum install --nogpgcheck bsf-2.3.0-11jpp.1.x86_64.rpm

16. Kill processes with one command

# ps -ef | grep lsnrctl | awk {'print $2'} | head -8
# kill -9 `ps -ef | grep conc | awk {'print $2'} | head -8`
# kill -9 `ps -ef | grep -i conc | grep -v grep | awk {'print $2'} | head -8`
# echo ps -eaf |grep -v grep | grep conc| grep FND | awk '{print $2}' | xargs kill -9 >> test.sh
# ps -eaf |grep -v grep | grep conc| grep FND | awk '{print $2}' | xargs kill -9

17. tar command
a.) Create a new tar archive.
$ tar cvf archive_name.tar dirname

eg:

[oracle@edolraclin1 fullbkup]$ tar -cvf u04testdata.tar /u04/test/data

[root@edolraclin1 fullbkup]$ tar -cvf u03test.tar /u03/test



 
b.) Extract from an existing tar archive.
$ tar -xvf archive_name.tar

c.) View an existing tar archive.
$ tar -tvf archive_name.tar

18. sendmail Configuration
# vi /etc/mail/sendmail.mc file and add the below 

define(`SMART_HOST', `smtpservername.companydomainname')
MASQUERADE_AS(`companydomainname')
FEATURE(masquerade_envelope)

Install this rpm package for sendmail to work

# rpm -ivh sendmail-8.13.8-8.el5.x86_64.rpm# rpm -ivh sendmail-cf-8.13.8-8.1.el5_7.x86_64.rpm

# make -C /etc/mail


# vi /etc/mail/access

# Check the /usr/share/doc/sendmail/README.cf file for a description of the format of this file. (search for access_db in that file)
# The /usr/share/doc/sendmail/README.cf is part of the sendmail-doc package.

# by default we allow relaying from localhost...
Connect:localhost.localdomain     RELAY
Connect:localhost                       RELAY
Connect:127.0.0.1                       RELAY
Connect:edolraclin1.domainname RELAY
Connect:smtpmailserver.domainname           RELAY
AuthInfo:smtpmailserver.domainname "U:samiora@gmail.com" "I:samiora@gmail.com" "P:passwordhere" "M:LOGIN PLAIN"
  
# /etc/init.d/sendmail restart

Shutting down sm-client:                                   [  OK  ]
Shutting down sendmail:                                    [  OK  ]
Starting sendmail:                                         [  OK  ]
Starting sm-client:                                        [  OK  ]

NOTE: The server from which the email to be sent should be added/allowed from Exchange server and security should add the IP address of the server to the internal relay group on the firewall F5.

19. touch command
 Below command can be used to change the accessed and modified date of a file.
# touch -a -m -t 201601011530.00 a.txt

-a = accessed
-m = modified
-t  = timestamp - use YYYYMMDDhhmm[.ss] time format

20. Miscellaneous commands


a.) # factor – factor of a number will be displayed

b.) # rev - reverses each lines text of a file

c.) # yes - output a string repeatedly until killed

d.) nice - runs a program with modified scheduling priority. Run COMMAND with an adjusted niceness, which affects process scheduling.  With no COMMAND, print the current  niceness. Nicenesses  range from -20 (most favorable scheduling) to 19 (least favorable).

# nice man women
No manual entry for women :-)

e.)
# pushd .
# popd {To goback to pushd directory}
# cd {To goback to the previous directory}

f.)
# !! {To run last command}
# !! | grep Linux --color {search for Linux string and color/highlight it}
# !12 {To run history command number 12, to check all the command history use ‘history’ command}


g.) Delete all files except few
# rm !(*.abc|*.xyz)  {here ! is not these *.abc and *.xyz files}

h.) Change file stat

stat a.txt
 

File: 'a.txt'
Size: 4425            Blocks: 24         IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 155615242   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-01-04 11:37:37.000000000 +0400
Modify: 2014-12-28 15:19:58.000000000 +0400
Change: 2014-12-28 15:19:58.000000000 +0400

# touch -d "9am" a.txt
# stat a.txt
It will show file is created at 9am


# touch -d "9:30am" a.txt

# touch -d "9:30:55am" a.txt

i.) To escape aliased version of a command using \


# \ls

j.) Run ./program and puts output in logfile and also display simultaneously on the output screen.=
# ./program | tee logfile

k.) Command to unlock the user that is locked due to invalid login attempts,
 
# pam_tally2 -r -u oracle

l.) Security Issues log file

# more /var/log/secure
m.) /etc/inittab file describes how the INIT process should set up the system in a certain run-level.
# more /etc/inittab

Restart server and press 'e' for single user mode.

n.) Command to open browser with url,

# gnome-open http://localhost:901
# gnome-open http://localhost:631/admin

o.) Useful system-config utilities,

system-config-authentication
system-config-date
system-config-kickstart
system-config-network-cmd
system-config-printer
system-config-selinux
system-control-network
system-config-bind
system-config-display
system-config-language
system-config-network-gui
system-config-rootpassword
system-config-services
system-config-bind-gui
system-config-httpd
system-config-lvm
system-config-network-tui
system-config-samba
system-config-soundcard
system-config-boot
system-config-kdump
system-config-netboot
system-config-nfs
system-config-securitylevel
system-config-time
system-config-cluster
system-config-keyboard
system-config-network
system-config-packages
system-config-securitylevel-tui
system-config-users
setup

p.) Telnet configuration start/stop

# /sbin/chkconfig ekrb5-telnet off
# /sbin/chkconfig krb5-telnet off

# /sbin/chkconfig ekrb5-telnet on
# /sbin/chkconfig krb5-telnet on

# /sbin/chkconfig --list |grep telnet

ekrb5-telnet:   off
krb5-telnet:    off

q.) Few more commands


Command to know the server's fingerprints

[root@edolraclin1 ssh]# ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub



2048 12:34:ba:e6:c1:a5:fc:87:39:a5:87:dc:96:2e:bd:20 /etc/ssh/ssh_host_rsa_key.pub



-l display output

-f input_keyfile



# cd /home/root/.ssh/
# more known_hosts

AWK command to get only file names
# ls -ltr > /tmp/a.txt
# awk -F " " '/u01/oracle/ {print $9}' /tmp/a.txt

In the above,
-F --> delimeter
" " --> space delimeter
/u01/oracle/ --> regular expression to search
$9--> 9th position that is file name


Sendmail

# chkconfig sendmail on

# service sendmail start



xinetd

# cd /etc/xinetd.d

# service xinetd restart

# /etc/init.d/xinetd restart
firewall / iptables disable

iptables are firewall concept from Oracle Linux 7.2 onwards, to disable the firewall do the following

#systemctl stop firewalld.service
#systemctl disable firewalld.service
Now remove symbolic link /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Now remove symbolic link /etc/systemd/system/basic.target.wants/firewalld.service.


grub
# vi /boot/grub/grub.conf
Edit this file to change the boot sequence of the kernels
default=0 {This means the first kernel in the list will be loaded}
timeout=5 {During the startup of the server it will wait for 5 seconds on the screen to select the kernel to load}

md5sum
# md5sum <filename> {to get the md5 check sum signature}

file
# file <filename> {to get information about type of file eg: uucp: ASCII text}

rpcinfo - makes an RPC call to an RPC server and reports what it finds
# rpcinfo -p nfsserver1
# showmount -e nfsserver1

disable services not required on the server using systemctl utility
systemctl disable bluetooth.service
systemctl disable libvirtd.service
systemctl disable NetworkManager.service
systemctl disable lvm2-monitor.service
systemctl disable lvm2-lvmetad.service
systemctl disable rdma.service
systemctl disable lvm2-lvmetad.socket
systemctl disable lvm2-lvmpolld.socket
systemctl stop firewalld.service
systemctl diabled firewalld.service
systemctl disabled firewalld.service
systemctl disable firewalld.service

Shutdown the machine with user defined message

# shutdown -h now 'System is going down for replacement of primary memory'



Scheduling the shutdown with 24 hour format Schedule shutdown for 8 PM.
# shutdown -h 20:00

Similar to shutdown (halt), you also schedule a reboot at a specified time as shown below.
# shutdown -r 20:00

Cancel a running shutdown
You can cancel the running shutdown by using -c option as,
# shutdown -c

GNU Privacy Guard (GPG)
gpg2 is the OpenPGP part of the GNU Privacy Guard (GnuPG). It is a tool to provide digital encryption and signing services  using  the  OpenPGP standard.

# vi sami.txt
aaaaaaaaaaaaa
bbbbbbbbbbbb
ccccccccccc
dddddddddd
eeeeeeeee
ffffffff
ggggggg
hhhhhh
iiiii
jjjj
kkk
ll
m
nn
ooo
pppp
qqqqq
rrrrrr
sssssss
tttttttt
uuuuuuuuu
vvvvvvvvvv
wwwwwwwwwww
xxxxxxxxxxxx
yyyyyyyyyyyyy
zzzzzzzzzzzzzz

Create a new GPG encrypted file.
#gpg2 -c sami.txt
Above command will prompt for password phrase. A new file with .gpg extension will be created.

To open the file use the below command,
#gpg2 -v -d sami.txt.gpg
gpg: CAST5 encrypted data
gpg: encrypted with 1 passphrase
gpg: original file name='sami.txt'
aaaaaaaaaaaaa
bbbbbbbbbbbb
ccccccccccc
dddddddddd
eeeeeeeee
ffffffff
ggggggg
hhhhhh
iiiii
jjjj
kkk
ll
m
nn
ooo
pppp
qqqqq
rrrrrr
sssssss
tttttttt
uuuuuuuuu
vvvvvvvvvv
wwwwwwwwwww
xxxxxxxxxxxx
yyyyyyyyyyyyy
zzzzzzzzzzzzzz

gpg: WARNING: message was not integrity protected
#tree
.
|-- content
|   |-- app
|   |   `-- content
|   |       `-- WEB-INF
|   |           `-- classes
|   |               `-- oracle
|   |                   `-- apps
|   |                       |-- fnd
|   |                       |   |-- common
|   |                       |   `-- metadata
|   |                       `-- ota
|   |                           `-- admin
|   |                               `-- common
|   |                                   `-- util
|   `-- plan
|       `-- WEB-INF
Command to check the Linux Server Hardware brand / CPU Information / CPU Cores
[root@ed-olraclin1 ~]# dmidecode | grep -A3 'System Information'
System Information
        Manufacturer: HP
        Product Name: ProLiant BL460c Gen9
        Version: Not Specified

[root@ed-olraclin1 ~]# dmidecode | grep -i CPU
        Version: Intel(R) Xeon(R) CPU E5620 @ 2.40GHz
        Version: Intel(R) Xeon(R) CPU E5620 @ 2.40GHz

[root@ed-olraclin1 ~]# dmidecode | grep -i core
        Core Count: 4
        Core Enabled: 4
        Core Count: 4
        Core Enabled: 4


Miscellaneous commands
# runlevel
# systemctl | grep running

To Install Oracle Linux from a USB Stick refer to this blog  https://blogs.oracle.com/otn/how-to-install-oracle-linux-from-a-usb-stick

cal - displays a simple calendar
# cal -y { Displays current year 2015 Calendar }
 
Subscribe to my blog and I will email you Field Guides for Oracle Apps DBA r12 & Linux Administration.

And for any queries, please don't hesitate to contact me on samiappsdba@gmail.com

Happy New year 2015