67 lines
2.0 KiB
Plaintext
Executable File
67 lines
2.0 KiB
Plaintext
Executable File
# extract database names from oratab
|
|
cat /etc/oratab|grep -v "^#"|grep -v "N$"|cut -f1 -d: -s
|
|
|
|
# running SID
|
|
ps -ef | grep smon | grep -v grep | grep -v sed | awk '{print $NF}' | sed -n 's/ora_smon_\(.*\)/\1/p'
|
|
|
|
# check if substring exists in string
|
|
string='My long string'
|
|
if [[ $string == *"My long"* ]]; then
|
|
echo "It's there!"
|
|
fi
|
|
|
|
|
|
# To save both stdout and stderr to a variable:
|
|
# Note that this interleaves stdout and stderr into the same variable.
|
|
MYVARIABLE="$(path/myExcecutable-bin 2>&1)"
|
|
|
|
# To save just stderr to a variable:
|
|
MYVARIABLE="$(path/myExcecutable-bin 2>&1 > /dev/null)"
|
|
|
|
# XARGS usage
|
|
cat /etc/oratab| grep 12.1.0.2 | grep -v "^#"|grep -v "N$"|cut -f1 -d: -s | xargs -I{} echo myshell.sh -d {}
|
|
|
|
# test if a variable is in a set
|
|
if [[ "$WORD" =~ ^(cat|dog|horse)$ ]]; then
|
|
echo "$WORD is in the list"
|
|
else
|
|
echo "$WORD is not in the list"
|
|
fi
|
|
|
|
# Remove substring from string
|
|
echo "Hello world" | sed "s/world//g"
|
|
|
|
# Replace text in file in place
|
|
sed -i 's/myoldstring/thenewstring/g' move_34.sh
|
|
|
|
# Example with xargs and awk
|
|
cat out.txt | grep -v SUCCESSFULLY | awk -F ":" '{ print $1}' | sort -u | xargs -I{} echo "/dbfs_tools/TOOLS/admin/sh/db_pre_change_oh.sh -d {} -a fixall"
|
|
|
|
# Find the line number of the first occurance of a string in a file
|
|
awk '/YODAEXA_DGMGRL/{ print NR; exit }' /tmp/listener.ora
|
|
|
|
# How to replace an entire line in a text file by line number
|
|
# where N should be replaced by your target line number.
|
|
sed -i 'Ns/.*/replacement-line/' file.txt
|
|
|
|
# Uppercasing Text with sed
|
|
sed 's/[a-z]/\U&/g'
|
|
|
|
# Lowercasing Text with sed
|
|
sed 's/[A-Z]/\L&/g'
|
|
|
|
# Search a text in a file and print the line#
|
|
grep -n "Database Status:" /tmp/vpl.txt | awk -F ":" '{print $1}'
|
|
|
|
# echo without NEWLINE
|
|
echo -n $x
|
|
|
|
# ltrim using sed
|
|
cat /tmp/vpl.txt | grep 'Intended State' | awk -F ":" '{print $2}' | sed 's/^ *//g'
|
|
|
|
# tkprof multiple traces
|
|
ls -1 TRACES*.trc | while read FILE ; do tkprof $FILE $FILE.out; done
|
|
|
|
# get errors from a datapump log
|
|
cat impo_01.log | grep ORA- | awk -F ":" '{ print $1}' | sort -u
|