Friday 30 October 2015

Real Time Linux & Unix Useful Commands

Real Time Linux & Unix Useful Commands:
-------------------------------------------------------
compress Listener log file in Linux and real time useful commands:
=================================================
Unix Level Useful commands
=========================

Step:-1
-------
cd /u01/app/oracle/10.2.0/db_1/network/admin --- listener log location

du -sh *|sort -n

du -sh listener.log

Step:-2
-------
vi filecompress.sh

cd /u01/app/oracle/10.2.0/db_1/network/admin --- listener log location

cp listener.log listener_currentdate.log

cat /dev/null > listener.log

-- press esc key
:wq

Run the filecompress.sh in nohup
---------------------------------

nohup sh -x filecompress.sh > filecompress.log 2>> filecompress.err &

Step:-3
-------

gzip -9 listener_currentdate.log

du -sh *.gz

--- OR ---

tar -zcvf listener_currentdate.tar.gz listener_currentdate.log

du -sh *.tar.gz


All the platforms (Linux, Solaries, AIX,IBMAIX,Sunsolaries) and it is very useful editing commands:
===============================================================================================

vi Editor Commands
vi Editor Commands

$ vi <filename>

Option ==> Action
vi     ==> Starts editing session in memory.
vi     ==> Starts session and opens the specified file.
vi *   ==> Opens first file that matches the wildcard pattern. Use :n to navigate to the next matched file.
view   ==> Opens file in read-only mode.
vi -R  ==> Opens file in read-only mode.
vi -r  ==> Recovers file and recent edits after abnormal abort from editing session (like a system crash).
vi +n  ==> Opens file at specified line number n.
vi +   ==> Opens file at the last line.
vi +/  ==> Opens file at first occurrence of specified string pattern.

Common Techniques to Enter vi Insert Mode:

Enter Insert Command ==> Action

i ==> Insert text in front of the cursor.
a ==> Insert text after the cursor.
I ==> Insert text at the beginning of the line.
A ==> Insert text at the end of the line.
o ==> Insert text below the current line.
O ==> Insert text above the current line.

Useful vi Exit Commands

Exit Command ==> Action
:wq ==> Save and exit.
ZZ  ==> Save and exit.
:x  ==> Save and exit.
:w  ==> Save the current edits without exiting.
:w! ==> Override file protections and save.
:q  ==> Exit the file.
:q! ==> Exit without saving.
:n  ==> Edit next file.
:e! ==> Return to previously saved version.

Common Navigation Commands

Command               ==> Action
j (or down arrow)     ==> Move down a line.
k (or up arrow)       ==> Move up a line.
h (or left arrow)     ==> Move one character left.
l (or right arrow)    ==> Move one character right.
Ctrl+f (or Page Down) ==> Scroll down one screen.
Ctrl+b (or Page Up)   ==> Scroll up one screen.
1G ==> Go to first line in file.
G  ==> Go to last line in file.
nG ==> Go to n line number.
H  ==> Go to top of screen.
L  ==> Go to bottom of screen.
w  ==> Move one word forward.
b  ==> Move one word backward.
0  ==> Go to start of line.
$  ==> Go to end of line.

Common Options for Copying, Deleting, and Pasting Text

Option ==> Action
yy  ==> Yank (copy) the current line.
nyy ==> Yank (copy) n number of lines.
p   ==> Put yanked line(s) below the cursor.
P   ==> Put yanked line(s) above the cursor.
x   ==> Delete the character that the cursor is on.
X   ==> Delete the character to the left of the cursor.
dw  ==> Delete the word the cursor is currently on.
dd  ==> Delete current line of text.
ndd ==> Delete n lines of text
D   ==> Delete to the end of the current line.

Common Options for Changing Text

Option ==> Action
r  ==> Replace the character that the curser is on with the next character you type.
~  ==> Change the case of a character.
cc ==> Delete the current line and insert text.
C  ==> Delete to the end of the line and insert text.
c$ ==> Delete to the end of the line and insert text.
cw ==> Delete to the end of the word and insert text.
R  ==> Type over the characters in the current line.
s  ==> Delete the current character and insert text.
S  ==> Delete the current line and insert text.

Common Options for Text Searching

Option ==> Action
/ ==> Search forward for a string.
? ==> Search backward for a string.
n ==> Repeat the search forward.
N ==> Repeat the search backward.
f ==> Search forward for a character in the current line.
F ==> Search backward for a character in the current line.

:set number ==> Displaying Line Numbers

===================================================================

bg, fg and jobs Linux Commands

Every command you give is a job that is executed. A job can be suspended, placed in the background, moved back to the foreground or terminated.

While running a job you can        Shortcut
---------------------------            ----------
suspend a job                    ctrl+z

terminate a job                    ctrl+c

Function                            Command
--------                            ------------
Move a suspended job to the foreground        fg

Continue a suspended job in the background    bg

List all jobs                            jobs

Kill a job (%N where N is the job number)    kill %N && fg

Start a job directly in the background            command &

When you execute a unix shell-script or command that takes a long time, you can run it as a background job.

1. Executing a background job

$ find . -name "*.aud" -mtime +120 -exec rm {} \; &

2. Sending the current foreground job to the background using CTRL+Z and bg command
    step 1.Press 'CTRL+Z' which will suspend the current foreground job.
    step 2.Execute 'bg to' make that command to execute in background.

Press ‘CTRL+Z’
$ bg

3. View all the background jobs using jobs command.

$jobs

jobs    : lists the jobs that you are running in the background and in the foreground

jobs -p : list only the PID of process group leader

jobs -l : list only jobs that have change status since last notified by their status

jobs -r : resrict output to running jobs

jobs – s : restrict output to stopped jobs

4. Taking a job from the background to the foreground using fg command

$ fg

When executed without arguments, it will take the most recent background job to the below commands:

We have two Methods:

1. throw SCP:

$SCP -P <file Name> oracle@hostname:<destpath>/.

OR

Throw SFTP:

======================================================================================
SFTP

>sftp <user>@<hostname>
Connecting to <hostname>...
<user>'s Password:
sftp>pwd                   (remote working directory)
sftp>!pwd                  (local working directory)
sftp>cd /target/path/   (remote path)
sftp>pwd                   (remote working directory)
sftp>!ls -l                   (local working directory)
sftp>put <filename(s)>
Uploading <filename> to /target/path/<filename>
sftp>ls -l                    (remote location files)
sftp>bye


=============================================================================================
Linux Basic Commands at OS Level:
---------------------------------


!stty erase ^?

ORACLE_SID=`ps -ef | grep asm_smon | grep -v 'grep' | grep -v 'sed' | awk '{printf $8}' | awk 'BEGIN{FS="_"} {printf $3}'`

date

env

uptime

who -b

last | grep -i boot

ps -ef | grep pmon

ps -ef | grep tns

ps -ef | grep d.bin

df -h or df -g

uname

/etc/oratab or /etc/var/oracle/oratab

df -kh or df -kh . or df -kh /mountpoint/

du -sh * or du -sh .

du -sg *

ls -ltrh <filename> | sort -n

ls -ld

tellme system

lsof /mountpoint/

find /home -name oraInventory -print

find . -name "*.gz" -depth -mtime +60 -exec rm {} \;

nslookup

tnsping

top

bg, fg, jobs

===========================

It find the particular file locations using below commands
-----------------------------------------------------------------


To find a file/directory
------------------------
find /home -name oraInventory -print

find /home|grep oraInventory

To delete files older than 60 days
----------------------------------
find . -name "*.gz" -depth -mtime +60 -exec rm {} \; 

Take the backups using the below commands(Oracle Home backups & Listner backups)

=================================================================================

TAR(Realtime commands):


tar -cvf newname.tar directory_name (to tar)
tar -xvf filename.tar (to untar)

========================================================

 COMPRESS & Delete FILES at OS LEVEL:
==================================

To list files dated Apr 24
--------------------------
ls -lrt | grep 'Apr 24' | awk -F' ' '{print$9}'

To delete files dated Apr 24
----------------------------
rm -rf `ls -lrt | grep 'Apr 24' | awk -F' ' '{print$9}'`

To list files of Month Apr
--------------------------
ls -lrt | grep 'Apr' | awk -F' ' '{print$9}'
ls -lrt *.trc|grep 'Apr'|xargs rm -rf  {}\;

To delete files of Month Apr
----------------------------
rm -rf `ls -lrt | grep 'Apr' | awk -F' ' '{print$9}'`

To list files older than 60 days
--------------------------------
find . -name "*.trc" -depth -mtime +60 -exec ls -l {} \; 
find /path/to/files* -mtime +60 -print

To delete files older than 60 days
----------------------------------
find . -name "*.trc" -depth -mtime +60 -exec rm {} \; 
find /path/to/files* -mtime +60 -exec rm {} \;
find /path/to/files* -type f -mtime +60 -print0 | xargs -r rm -rf

Below COMPRESS command::
-----------------------
nohup compress *.arc &

ls -lrt *.arc|awk '{print "compress "$9}' >ARC_LIST.txt

SOURCE : Internet

References:

http://eisabainyo.net/weblog/useful-linux-commands/


=================================================================
 REBOOT Server:
===============
If its Dataguard setup or normal db, following steps mandatory just take backup of following three steps and store it in separate notepad. once server reboot activity 

completed cross check once which was taken before server reboot.
===============================================================

ps -ef|grep pmon  

ps -ef|grep pmon|wc -l

ps -ef|grep inh (OR) ps -ef|grep tns

ps -ef|grep inh|wc -l

ps -ef |grep d.bin

hostname

date

uname -a

cat /etc/oratab  /  cat /var/opt/oracle/oratab

uptime 

who -b

df -h  / df -gt
-------------------------------------------------------------------------------------------
Reboot Server  time database side need to  check the below commands: 

(Before server reboot and after server boot, if its is DG database)
-------------------------------------------------------------------

SQL> select name,db_unique_name,database_role,controlfile_type,CREATED from v$database;

SQL >select sequence#,first_time,next_time,completion_time,applied from v$archived_log where applied <> 'YES' and DEST_ID !=0 and status!='D'and completion_time <

(sysdate-1/48) Order By 1;

no rows selected----->in sync

SQL >select process, status ,sequence# from v$managed_standby;

MRP0---->process should reflect

===============================
Realtime Data Guard Db Startup Procedure
===============================

Sqlplus “/ as sysdba”

startup nomount;

alter database mount standby database;

recover managed standby database disconnect from session; ----------->To put it in MRM MODE

exit;

=================================
Realtime Data Guard Db  Shutdown Procedure
=================================

Login as oracle

source the environment

sqlplus “/ as sysdba”

alter database recover managed standby database cancel; ------> to cancel MRM mode

shutdown immediate;
==================================================


No comments:

Post a Comment