Work :
CPU : ps -eo pid,ppid,user,tty,cmd,%mem,%cpu --sort=-%cpu | headMem : ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | headfind : find . -type f -name "*.aud" -newermt 2021-03-06 ! -newermt 2021-03-11 -exec gzip {} \;find . -newermt 2021-02-15 ! -newermt 2021-02-21 -exec ls -l {} \;find . -newermt 2021-02-15 ! -newermt 2021-02-21 -exec r {} \;find . -newermt 2021-02-15 ! -newermt 2021-02-21 | xargs tar -rvf 2021-02-15to20.tar.gztar : find . -name 'c*.trm' 'c*.trc' -mtime +30 | xargs tar -czvf oldfile.tar.gzfind . -newermt 2021-02-15 ! -newermt 2021-02-21 | xargs tar -rvf 2021-02-15to20.tar.gztar cvf log.xml_11252020_01.gz log_1?.xmltar cvzf all_files.tar.gz my_first_file my_second_file ... my_last_filetar -cvf files.tar my_directory --remove-filesvmstat– Statistics about virtual memory and cpu/hard disk usage. vmstat 5 6tprof – Detailed profile of CPU usage by an application.svmon - Virtual memory monitor . Useful for determining which processes are using the most memory.sar - System Activity Recorder utility monitors cpu, IO etcpstat – Statistics about system attributes.how much paging is in use.lsps – Report statistics about paging space.
alias fdf="df -h d??|sort +4 -5n"
alias fcf="df -h|sort +4 -5n"
alias faf="df -h|sort +3 -4n"
awk '/reading from backup piece/{print;getline;print;}' DUPLICATE.log_error
Tar
cd /oracle/app/product/11.2.0/dbhome_1
tar cvf - . | ( ssh lnx2 "cd /oracle/app/product/11.2.0/dbhome_1 ; tar xvf -" )
Cpu
prstat -maLv
df (no line wrapping)
printf "%s\n" "$(df -h)"
Check cpu and cores : Linux
less /proc/cpuinfo
egrep "^physical" /proc/cpuinfo| sort|uniq|wc -l --gives physical cpu
egrep "^physical" /proc/cpuinfo > pid
egrep "^core id" /proc/cpuinfo > cid
paste pid cid |sort |uniq | wc -l --gives cpu cores
wc -legrep "^process" /proc/cpuinfo |wc -l -- gives logical
Solaris : T series
number of physical cpu : "psrinfo -p" or kstat cpu_info | grep chipid| sort -u | wc -l
/usr/bin/kstat -m cpu_info | egrep "chip_id"|awk '{ print $2 }' | sort -u | wc -l
number of cores : "kstat cpu_info | grep core_id | sort -u | wc -l"
/usr/bin/kstat -m cpu_info | egrep "core_id"|awk '{ print $2 }' | sort -u | wc -l
number of threads : "psrinfo -pv"
/usr/bin/kstat -m cpu_info | egrep "module: cpu_info"|awk '{ print $4 }' | sort -u | wc -l
psrinfo -pv
Listener Error : grep "15-JAN" listener.log | awk '{ if ( $NF != 0 ) print $0 }'
Other scripts :
To display complete ps output : /usr/ucb/ps -alxwww
fdf() { df -h|sort +4 -5n ; }
pmon() { ps -ef| grep _pmon |grep -v grep ; }
sid() { echo $ORACLE_SID ; }
oh() { echo $ORACLE_HOME ; }
ltt() { ls -ltr ; }
bdump() { cd /app/oracle/admin/$ORACLE_SID/bdump ;pwd ;}
err() { tail -1000 /app/oracle/admin/$ORACLE_SID/bdump/alert_$ORACLE_SID.log|egrep -in "ORA-error" ;}
ps -ef |grep pmon |cut -d "_" -f3 |grep -v pmon
awk '/select/,/from/' locks.sql
/usr/bin/echo "\nProcess Still running... \n" `ps -eaf|grep rman|grep -v grep` "\n\nSo far completed out of :"`ls -l /d??/oradata/sid/*.* |wc -l` "\n" `/usr/bin/df -h|sort +4 -5n |grep 9[0-9]%`
Change linux putty color
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
fi
checkdb.ksh :
#!/bin/ksh
export ORACLE_SID=${1}
export CHKSTATUS=${2}
export ORAUSER=dba
export SCRIPTDIR=/app/oracle/scripts
export ORAPASS=`grep -i $ORAUSER $SCRIPTDIR/passwd/passwd.file | grep -v sys | cut -f2 -d:`
. /app/oracle/scripts/env/.oraenv
#DBALIST=xyz@abc.com
export LOGDIR=$SCRIPTDIR/logs
export LOGFILE=$LOGDIR/chkdb_${ORACLE_SID}.log
st="Shutting down instance: further logons disabled"
mt="Completed: *alter *database *mount"
op="Completed: *alter *database *open"
alog="/app/oracle/admin/${1}/bdump/alert_${1}.log"
lastcmd=`egrep -i "$st|$mt|$op" $alog|tail -1|egrep -i "$CHKSTATUS|open"`
#egrep -i "$st|$mt|$op" $alog|tail -1|grep -i $CHKSTATUS
if [ -n "$lastcmd" ]
then
echo `date ` "Database ${ORACLE_SID} last status ${lastcmd}" >> $LOGFILE
else
echo "`date` : Database ${ORACLE_SID} not yet in $CHKSTATUS state.It may be hanging during rman backup." >> $LOGFILE
#echo "`date` : Database ${ORACLE_SID} not yet in $CHKSTATUS state.It may be hanging during rman backup."
mailx -s "Database ${ORACLE_SID} not yet in $CHKSTATUS state.It may be hanging during rman backup." ${DBALIST} < /dev/null
fi
dbase_up.ksh
#!/usr/bin/ksh
st="Shutting down instance: further logons disabled"
op="Completed: *alter *database *open"
cl="Completed: *ALTER *DATABASE *CLOSE *NORMAL"
mt="Completed: *alter *database *mount"
alog="/app/oracle/admin/${1}/bdump/alert_${1}.log"
#alog="/opt/oracle/diag/rdbms/${1}/${1}/trace/alert_${1}.log"
lastcmd=`egrep -i "$st|$mt|$op|$cl" $alog|tail -1`
export ORACLE_SID=${1}
export SCRIPTDIR=/app/oracle/scripts
export LOGDIR=$SCRIPTDIR/logs
export LOGFILE=$LOGDIR/db_up_${ORACLE_SID}.log
export UTIL_SCRIPT_DIR=$SCRIPTDIR/utils
. /app/oracle/scripts/env/.oraenv
DBALIST=xyz@abc.com
copen=`egrep -i "$st|$mt|$op|$cl" $alog|tail -1|egrep -i "open"|wc -l`
cmount=`egrep -i "$st|$mt|$op|$cl" $alog|tail -1|egrep -i "mount"|wc -l`
cclose=`egrep -i "$st|$mt|$op|$cl" $alog|tail -1|egrep -i "CLOSE NORMAL"|wc -l`
if [ $copen -eq 1 ]
then
echo "`date` : DB already up and running" >> $LOGFILE
#echo "`date` : DB already up and running"
mailx -s "Database ${ORACLE_SID} was already up and running" ${DBALIST} < ${LOGFILE}
elif [ $cclose -eq 1 ]
then
echo DB is not open.Now starting.. >> $LOGFILE
$UTIL_SCRIPT_DIR/dbora.ksh start ${ORACLE_SID} 2&>1 >> ${LOGFILE}
sleep 120
echo "`date`" >> $LOGFILE
egrep -i "$st|$mt|$op|$cl" $alog|tail -1 >> $LOGFILE
mailx -s "Database ${ORACLE_SID} was not open.Now starting..." ${DBALIST} < ${LOGFILE}
elif [ $cmount -eq 1 ]
then
echo "`date` : DB is in mount state" >> $LOGFILE
echo "`date` : Logging into the database to start" >> $LOGFILE
sqlplus -s /nolog <<EOF 2>&1 1>> $LOGFILE
connect /as sysdba
alter database open;
EOF
egrep -i "$st|$mt|$op|$cl" $alog|tail -1 >> $LOGFILE
mailx -s "Database ${ORACLE_SID} was in mount state.Now starting..." ${DBALIST} < ${LOGFILE}
fi
duplicate_dbase.ksh
#!/bin/ksh
export ORACLE_SID=DBQA
. /app/oracle/scripts/env/.oraenv
export SCRIPT_DIR=/app/oracle/scripts/
export LOG_DIR=/app/oracle/scripts/
export TODAY=`date +%d-%b-%y`
export RMAN_LOGFILE=${LOG_DIR}/DUPLICATE_${ORACLE_SID}_${TODAY}.log
date>>$RMAN_LOGFILE
rman auxiliary / target sys/sys_prodpasswd@tns4prod >>$RMAN_LOGFILE <<EOF
run {
allocate auxiliary channel ch1 type disk;
allocate auxiliary channel ch2 type disk;
allocate auxiliary channel ch3 type disk;
allocate auxiliary channel ch4 type disk;
set newname for datafile 87 to "/d27/oradata/DBQA/user_temp.dbf";
DUPLICATE TARGET DATABASE TO DBQA NOFILENAMECHECK UNTIL TIME "to_date('11/10/2015 00:55:00','mm/dd/yyyy hh24:MI:SS')";
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
exit
EOF
Monitor mount points
#!/bin/ksh
host=`hostname`
ip=`nslookup $host | grep "Address" | tail -1 | awk '{ print $2 }'`
date=`date`
logfile=$LOGLOCN/logs/MountPoint_monitor.lst
touch $logfile
echo "Report on: $host">$logfile
echo "IP Address : $ip">>$logfile
echo "Date & Time : $date">>$logfile
echo "Following Filesystems on $host server have less than free space: ">>$logfile
echo >>$logfile
df -h |head -1 >> $logfile
#echo -e "--------------------------------------------------------------------------------------------------------\n">>$
logfile
df -h|grep datammount|tr -s " """|awk '{if($3<=9) {print $0}}' FS="G" >>$logfile
Count=`cat $logfile|wc -l`
echo $Count
if [ $Count -gt 6 ];then
mailx -s "File Systems with less free space on $host" "email@dba" <$logfile
fi
exp_tables.sh
/usr/sbin/mknod /tmp/epipe.$$ p
exp parfile=exp_tables.par file=/tmp/epipe.$$ log=/d24/oradata/dmp/tablename.log
gzip < /tmp/epipe.$$ > /d02/oradata/dmp/tablename.gz
rm /tmp/epipe.$$
exp_tables.par
userid=userid/passwd@tnsstring
buffer=2097152,
direct=y,
tables=(
schema.tablename
),
constraints=y,
grants=y,
indexes=n
rows=y
impdp_table.sh
impdp DUMPFILE=tablename.dmp PARFILE=impdp_table.par
imp_table.par
userid=userid/passwd@tnsstring
buffer=20971520,
ignore=y,
full=y,
commit=y,
constraints=y,
grants=y,
indexes=y,
rows=y
m.ksh
Check memory of instance in Linux by by Marc Billette
#!/bin/ksh
#based on explanations of pmap in http://www.makelinux.co.il/books/lkd2/ch14lev1sec2
#Verify the parameter count
if [ $# -lt 2 ]; then
echo "Usage: $0 ORACLE_SID [long|columnar]
echo " e.g.: $0 PROD columnar
exit 1
fi
#Set variables
export ORACLE_SID=$1
output_type=$2
#running calculations...
export pids=`ps -elf|grep oracle$ORACLE_SID|grep -v grep|awk '{print $4}'`
export countcon=`print "$pids"|wc -l`
if [ "`uname -a|cut -f1 -d' '`" = "Linux" ]; then
export tconprivsz=$(pmap -x `print "$pids"`|grep " rw"|grep -Ev "shmid|deleted"|awk '{total +=$2};END {print total}')
else
export tconprivsz=$(pmap -x `print "$pids"`|grep " rw"|grep -v "shmid"|awk '{total +=$2};END {print total}')
fi
export avgcprivsz=`expr $tconprivsz / $countcon`
if [ "`uname -a|cut -f1 -d' '`" = "Linux" ]; then
export instprivsz=$(pmap -x `ps -elf|grep ora_.*_$ORACLE_SID|grep -v grep|awk '{print $4}'`|grep " rw"|grep -Ev "shmid|deleted"|awk '{total +=$2};END {print total}')
else
export instprivsz=$(pmap -x `ps -elf|grep ora_.*_$ORACLE_SID|grep -v grep|awk '{print $4}'`|grep " rw"|grep -v "shmid"|awk '{total +=$2};END {print total}')
fi
if [ "`uname -a|cut -f1 -d' '`" = "Linux" ]; then
export instshmsz=$(pmap -x `ps -elf|grep ora_pmon_$ORACLE_SID|grep -v grep|awk '{print $4}'`|grep -E "shmid|deleted"|awk '{total +=$2};END {print total}')
else
export instshmsz=$(pmap -x `ps -elf|grep ora_pmon_$ORACLE_SID|grep -v grep|awk '{print $4}'`|grep "shmid"|awk '{total +=$2};END {print total}')
fi
export binlibsz=$(pmap -x `ps -elf|grep ora_pmon_$ORACLE_SID|grep -v grep|awk '{print $4}'`|grep -v " rw"| awk '{total +=$2};END {print total}')
export sumsz=`expr $tconprivsz + $instprivsz + $instshmsz + $binlibsz`
if [[ "$output_type" = "long" ]]; then
echo memory used by Oracle instance $ORACLE_SID as of `date`
echo
echo "Total shared memory segments for the instance..................: "$instshmsz KB
echo "Shared binary code of all oracle processes and shared libraries: "$binlibsz KB
echo "Total private memory usage by dedicated connections............: "$tconprivsz KB
echo "Total private memory usage by instance processes...............: "$instprivsz KB
echo "Number of current dedicated connections........................: "$countcon
echo "Average memory usage by database connection....................: "$avgcprivsz KB
echo "Grand total memory used by this oracle instance................: "$sumsz KB
echo
elif [ "$output_type" = "columnar" ]; then
printf "%17s %10s %10s %10s %10s %10s %10s %10s %10s\n" "date" "ORACLE_SID" "instshmsz" "binlibsz" "tconprivsz" "instprivsz" "countcon" "avgcprivsz" "sumsz"
echo "----------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------"
printf "%17s %10s %10s %10s %10s %10s %10s %10s %10s\n" "`date +%y/%m/%d_%H:%M:%S`" $ORACLE_SID $instshmsz $binlibsz $tconprivsz $instprivsz $countcon $avgcprivsz $sumsz
fi;
asmdu.sh
export ORAENV_ASK=NO
export ORACLE_SID=`ps -ef|grep pmon_+ASM |grep -v grep |awk
-F"_" '{ print $NF;}'`
. oraenv
echo "------Main Report--------"
asmcmd lsdg | awk 'BEGIN { print
"\nSize\tUsed\tAvail\tUse%\tName" getline } { printf" %s
\t%.0f\t %.0f %.0f'%' \t%s \n" ,$7/1024
,$7/1024-$8/1024 , $8
/1024, ($7-$8)*100/$7, $12}'
echo
for m in $(asmcmd ls + | awk -v z='+' '{ print z$0 }'
|egrep '/$' );
do
echo -e "$m \t `asmcmd du $m | awk 'BEGIN
{getline } { printf"%.0fGB\n" ,$2/1024}'`"
done
echo
echo "----Detailed Report------"
for dg in $(asmcmd ls + | awk -v z='+' '{ print z$0 }'
|egrep '/$' );
do
#echo -e "$dg \t `asmcmd du $dg |
awk 'BEGIN {getline } { printf"%.0fGB\n"
,$2/1024}'`"
printf "%-20s %-20s \n" $dg
`asmcmd du $dg | awk 'BEGIN {getline } { printf"%.0fGB\n"
,$2/1024}'`
#asmcmd ls $dg| awk -v y=$dg '{ print y$0
}'|egrep '/$';
for db in $(asmcmd ls $dg| awk -v y=$dg
'{ print y$0 }'|egrep '/$';)
do
#echo -e "$db \t `asmcmd du
$db | awk 'BEGIN {getline } { printf"%.0fGB\n"
,$2/1024}'`"
printf "\t%-20s %-20s \n"
$db `asmcmd du $db | awk 'BEGIN {getline } {
printf"%.0fGB\n" ,$2/1024}'`
done
#echo -------------
for cdir in $(asmcmd ls $dg| awk -v y=$dg '{ print y$0
}'|egrep '/$');
do
#asmcmd ls $cdir| awk -v x=$cdir '{ print x$0
}'|egrep '/$';
printf "\t\t%-20s\n" `asmcmd ls
$cdir| awk -v x=$cdir '{ print x$0 }'|egrep '/$';`
done
echo
done