Thursday, 5 December 2013

Unix Commands


1> List and remove all files older than 30 days
                 
find /u01/local/logs -mtime +30 -exec ls -l {} \;
find /u01/local/logs -mtime +30 -exec rm {} \;  
 
2> Tar and gzip commands
 
tar and compress a bunch of datafiles and then untar and uncompress them
cd /u02/oradata/test- (area of database files )
Now tar and compress and copy the files to backup area – /u02/oradata/test_bkup and name the file as test.tar.gz
tar cvf – * |gzip -c >/u02/oradata/test_bkup/test.tar.gz –
cd /u02/oradata/test_bkup > ls -lrt
-rw-r–r– 1 ofsad1 dba 105952962 Feb 26 11:31 test.tar.gz
Now to untar and uncompress the files back to the original area -
cd /u02/oradata/test
gzip -dc < /u02/oradata/test_bkup/test.tar.gz | tar xvf -

3> Locating Files under a particular directory
find . -print |grep -i test.sql

4> Using AWK in UNIX
To remove a specific column of output from a UNIX command – for example to determine the UNIX process Ids for all Oracle processes on server (second column)
ps -ef |grep -i oracle |awk ‘{ print $2 }’

5> Changing the standard prompt for Oracle Users
Edit the .profile for the oracle user
PS1=”`hostname`*$ORACLE_SID:$PWD>”

6> Display top 10 CPU consumers using the ps command
/usr/ucb/ps auxgw | head –11

7> Show number of active Oracle dedicated connection users for a particular ORACLE_SID
ps -ef | grep $ORACLE_SID|grep -v grep|grep -v ora_|wc –l

8> Display the number of CPU’s in Solaris
psrinfo -v | grep “Status of processor”|wc –l

9> Display the number of CPU’s in AIX
lsdev –C | grep Process|wc –l

10> Display RAM Memory size on Solaris
prtconf |grep -i mem

11> Display RAM memory size on AIX
First determine name of memory device
lsdev -C |grep mem
then assuming the name of the memory device is ‘mem0’
lsattr -El mem0

12> Swap space allocation and usage
Solaris : swap -s or swap -l
Aix : lsps -a

13> Total number of semaphores held by all instances on server
ipcs -as | awk ‘{sum += $9} END {print sum}’

14> View allocated RAM memory segments
ipcs -pmb

15> Manually deallocate shared memeory segments
ipcrm -m ‘ID’

16> Show mount points for a disk in AIX
lspv -l hdisk13

17> Display amount of occupied space (in KB) for a file or collection of files in a directory or sub-directory
du -ks * | sort -n| tail

18> Display total file space in a directory
du -ks

19> Cleanup any unwanted trace files more than seven days old
find . *.trc -mtime +7 -exec rm {} \;

20> Locate Oracle files that contain certain strings
find . -print | xargs grep rollback

21> Locate recently created UNIX files (in the past one day)
find . -mtime -1 –print

22> Finding large files on the server (more than 100MB in size)
find . -size +102400 -print

23> Crontab :
To submit a task every Tuesday (day 2) at 2:45PM
45 14 2 * * /opt/oracle/scripts/tr_listener.sh > /dev/null 2>&1
To submit a task to run every 15 minutes on weekdays (days 1-5)
15,30,45 * 1-5 * * /opt/oracle/scripts/tr_listener.sh > /dev/null 2>&1
To submit a task to run every hour at 15 minutes past the hour on weekends (days 6 and 0)
15 * 0,6 * * opt/oracle/scripts/tr_listener.sh > /dev/null 2>&1

24> Remove file with unseen characters
This works on AIX – Please test on other systems.
If a file name is vague and can’t be removed.
Ex – a file name has some hidden characters which prevents it’s removal as the name is not recognized by the rm command.
ls -lai sqlnet.log
19462 -rw-r—– 1 oraofsap dba 7741 Jun 4 13:14 sqlnet.log
look for number against file and rm number .
find . -inum 19462 -exec rm {} \;

25> How to kill all similar processes in Unix
In this example all opmn processes are being killed. This command is useful if we find a lot of processes still present at the OS level even after shutting down in this case the Oracle Application Server
ps -ef | grep opmn |grep -v grep | awk ‘{print $2}’ |xargs -i kill -9 {}
 

No comments:

Post a Comment