Friday, July 18, 2008

Useful Unix Commands and Scripts for DBA's

Find/Zip/Move/Delete files older than x days

find ./ -name "*.ARC" -mtime +1 -exec ls -l {} \;
find ./ -name "*.ARC" -mtime +1 -exec rm {} \;
find ./ -name "*.ARC" -mtime +1 -exec gzip {} \;


find ./ -name "*.arch" -mtime +1 -exec mv {} /u01/andy/;

Delete the 500 oldest files

rm -f `ls -trhead -500`

Find and grep

find ./ -exec grep -l "string" {} \;

Check all logs for ORA- errors

grep ^ORA- *log cut -f2 -d"-"cut -f1 -d:awk '{print "ORA-" $1}'sort -u


INODE:

ls -latri
find . -inum -print;
find . inum \ -exec -exec rm -i {} \;

How to remove whitespace in file from vi editor

:%s/[ctrl+v ctrl+m]//g

Get Oracle HOME from oratab:

cat /etc/oratabegrep ':N:Y'grep -v \*cut -f2 -d':'



Resync Command:

rsync -e ssh -Pazv /u01/app/oracle/admin/slice/arch/ oracle@test1:/u01/app/oracle/admin/slice/arch/



Error:

***An error occured during the file system check
***Dropping you to a shell, the system will reboot
***When you leave the shell
Give root password for maintenance
Or type Control-D to continue:


Solution:
#Give root password
#mount -o remount,rw /
#comment in /etc/fstab file


Create New Filesystem:

mkfs -t ext3 /dev/sde1
mkdir /software
mount -t ext3 /dev/sdb1 /software
add following line on /etc/fstab
/dev/sdb1 /software ext3 defaults 1 1   

No comments: