Friday, 9 November 2012

Handy scripts

 Purge alert log file

tail -n100000 alert_PROD.log > 1.log ; mv alert_PROD.log alert_PROD.log_old ;
cp 1.log alert_PROD.log ;

Find all files and move to directory

find . -type f -exec mv {} ./old_logfiles/ \;
find . -mtime +250 -type f -exec rm -rf {} \;
find -name "*.sh" -type f | xargs  grep 'Xms768m'

CD to directory and untar files recursively

for i in `ls ` ; do cd $i;j=`ls`;echo $j;tar -xvf $j ;cd ../; done;

for i in `ls`;do let k=($k+1) ;mkdir $k;mv $i $k; cd $k;tar -xvf $i;cd ../ ; done;

Backup current directory and create similar:

cd /u02/oraprod
echo "Move current backup"
mv PROD_hotbkp  "PROD_hotbkp_"`date +"%m-%d-%Y"`
mkdir PROD_hotbkp

Concurrent Request

kill -9 `ps -ef|grep FNDLIBR|grep -v grep|awk '{print $2}'`

Grep search and kill process

ps -ef | grep FNDL | awk '{print "kill -9 "$2 }'

Send Mail

mail -s "testing Mail" karthikeyanc.gdc@petrofac.com < one.html

BASH  promt 

export PS1="${USER}@${HOSTNAME}:${PWD}$"

Get TNS STRING

tnsping $TWO_TASK | grep 'Attempting to contact' | sed -e "s,Attempting to contact ,$TWO_TASK=,g"

Apps Password

history | grep apps/ | grep -v grep |grep 'sqlplus' | tail -n1 | awk '{print $3}'

Backup APPS and INST 

cd $APPL_TOP/../../../ ; nohup tar -cf - apps | gzip > /u02/applprod/PROD_apps_coldbkp/"$TWO_TASK"_apps_coldbkp_"`date +"%m-%d-%Y"`".tar.gz &

cd $INST_TOP/../../../ ; nohup tar -cf - inst | gzip > /u02/applprod/PROD_apps_coldbkp/"$TWO_TASK"_inst_coldbkp_"`date +"%m-%d-%Y"`".tar.gz &

Find version of the File ADident

find $APPL_TOP  -name "ap_trx_missing_event_fix.sql" -prune -o -path './admin' -exec adident Header {} \;
  

Find Weblogic Version

grep "WebLogic Server" $MW_HOME/registry.xml | grep version| awk '{print $4}' 

Find Apex Version

select comp_name, version, status from dba_registry where comp_name like '%Express%';

Restore unzip 

nohub cat /archive/backup/PROD_coldbkp_2Mar2013/db_tech_st11.tar.gz | gunzip | tar -xvf - &

Find most recent file created inside directory recursively
find  -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2 | tail -n 1

No comments:

Post a Comment