Thursday, September 2, 2010

linux Tips

To Change case(Translate command
=================================
$echo ${ORAID} | tr 'A-Z' 'a-z'
$ tr 'A-Z' 'a-z' <> newfile
To translate braces into parentheses, enter:
$tr '{}' '()' <> newfile


Run Command as diffrent user
$su orartp "-c crontab -l"
$sudo -u orartp crontab -l

Serach files and move them to seperate folder
==============================================

find . -mtime +7 -exec ls -ltr {} \; ==>Display files

find /usr/tivoli/cat_maint/log -mtime +2 -exec ls -ltr {} \;

find . -mtime +7 -exec mv {} /usr/tivoli/cat_maint/abc \;==>Moves files to diff folder

find . -mtime +7 -exec rm {} \; ==>Find and remove files.
AWK script Examples
=====================

Display 7th and 4th field seperated by
===================================
$df -g | grep oraarch | awk '{print $7 "==>" $4}'

$df -g | grep oraarch | awk '{print $7 "==>" $4 " Used ==>Free GB==>" $3}'

$ awk -f myscript.awk myfile.in

To change Permission file from find command
============================================
find . -type f -exec chmod -x '{}' \;

chmod -R o+x *

chmod -R g+x *

To display line which does not contain "/" at the start in a file
======================================================================

$cat init.ora |grep -v "^/"
$cat init.ora |grep -v "^#"

Searching for a particular Text in the directory and sub-directories under that
===================================================================================

$find . -name "*" -exec grep -il {} \; | tee

Find all files except owned by a specific user
=================================================
Will list the file names containing the search string.

$find . ! -user oracle9i -print

‘ ! ‘ negates the expression. The other example will list all the files not owned by user oracle9i.

Find files having some specific permission
============================================

$find . –name *.* -perm 664 -print


Searching for links in all the folders under the directory and output to a text file to create a script to change the links.
================================================================================================================================

$find . -type l -print -exec ls -trl {} \; | grep -i uat | awk '{ print $11, $9 }' | tee change_link.sh



Linux OS Service 'ntpd'
=========================
This service is handled by init.d script /etc/init.d/ntp.

Start the service as follows:

#/sbin/service ntpd start
# /sbin/service ntpd condrestart ==>Start it if not running

Stop the service as follows:

# /sbin/service ntpd stop

Check if the serivce is started or stopped:

# /sbin/service ntpd status

Determine which system run levels the service is active:

# /sbin/chkconfig --list ntpd

Configuration file is located @ /etc/sysconfig/ntpd

TO check what options its running with currently
#ps -o args -p `cat /var/run/ntpd.pid`

RPM Download
==================

http://ftp.riken.go.jp/Linux/cern/slc41/x86_64/yum/updates/repodata/repoview/binutils-0-2.15.92.0.2-25.html


To Run command as different User from root
===============================================

sudo -u orapid /home/orapid/1.sh

sudo -u orapid /usr/tivoli/cat_maint/cat_maint.sh

sudo -u orapid /usr/tivoli/cat_maint/cat_maint.sh PID



To display Server Info
=====================

$grep MemTotal /proc/meminfo
$uname -r
$fdisk -l ==>To list raw devices configured on the server

Display status of Raw Devices
=============================

#service rawdevices status


Linux Filesystems
====================

/etc/fstab displays filesystems on server which can be be mounted with mount command.


Running job in background and nohup.(nohup.out in current folder displays output of running process)
====================================

$nohup ./costress_daily_stat.sh &


Killing Stubborn Unix Tasks
==============================

$cat /dev/null > /dev/ttyname kill –9

Remarks: This command is indispensable when killing stubborn UNIX tasks.

To see When the Server was started
==========================================

$uptime

To see the previous logons and logoffs
======================================

$last

# last shutdown

# last root console

To shutdown the Server
===========================

$shutdown –Fr

Show number of active Oracle dedicated Connection Users
===========================================================

$ps –ef | grep $ORACLE_SID | grep –v grep | grep –v ora_ | wc -l

Determining the type of the file
====================================

$file or file *



Taking TAR Backup on Internal (Default) Tape Drive
==========================================================

Tested on AIX

$mt -f /dev/rmt1 rewind
cd /
$tar -cvf /dev/rmt0 ./prodr11i ./prod_dat ./prod_idx ./prod_msc

To view the list of files backed up

$tar –tvf /dev/rmt0

Installing, upgrading, removing, querying package using rpm in redhat
=========================================================================

To install a package (i=install v=verbose h=show hash marks) :-
#rpm -ivh

To uninstall (erase) a package
#rpm -e

To upgrade a package
#rpm -Uvh

To test a package to see how it would install (without installing, also checks dependencies)
#rpm -Uvh --test

To query whether a package has been installed or not
#rpm -qa | grep


To Open or block ports on RedHat Linux
=============================================

$/usr/sbin/lokkit


Displaying Allocated RAM Memory Segments in Unix
==================================================

$ipcs –pm (Inter process control system)



Export/Zip and Unzip/Import using UNIX Pipes
=================================================
To do this, you would create a pipe (using the unix mknod command), run the programs (in either order), with the first one in the background (using "&" at the end), which use that pipe like a file, and then remove the pipe. Below shows a full export to a zipped dump file:

$mknod /tmp/exp_pipe p
$gzip -cNf prod.dmp.gz &
$exp system/systempassword file=/tmp/exp_pipe full=y compress=n log=prod.dmp.log
$rm -f /tmp/exp_pipe

Below shows a full import with that zipped dump file:

$mknod /tmp/imp_pipe p
$gunzip -c prod.dmp.gz >/tmp/imp_pipe &
$imp system/systempassword file=/tmp/imp_pipe full=y ignore=y buffer=1024000 commit=y \
log=prod.log
$rm -f /tmp/imp_pipe

No comments:

Post a Comment