Useful Unix stuff, I have picked up on my travels.
When using vi on +ASM trace files you need to use the -- option.
e.g.:
vi -- +ASM_123.trc
otherwise vi won't work with the file.
using vi to delete to end of line (after a character, in this case ";") - e.g.
select sysdate from dual; --unwanted comment here
:1,$s/;.*/;/g
select sysdate from dual;
Similar using sed, delete everything after the hyphen
[oracle@usze2embtora2 ~]$ echo "The end of the world - not really" | sed s/\-.*//g
The end of the world
Remove blank lines :
:g/^$/d
To convert everything to uppercase -
:%s/.*/\U&/
If you want to convert everything to lowercase then all you need to do is change the U for an L.
:%s/.*/\U&/
If you want to convert everything to lowercase then all you need to do is change the U for an L.
tr command
see also : https://linuxize.com/post/linux-tr-command/
echo 'linuxize' | tr 'lin' 'red'
tr will replace each occurrence of l with r, i with e, and n with d.
tr will replace each occurrence of l with r, i with e, and n with d.
i.e.
reduxeze
Explode / Backticks usage :
In addition to the explode or backticks
`command`
you can use $(command)
or "$(command)"
which is easier to read, and allow for nesting.OUTPUT="$(ls -a1)"
echo "${OUTPUT}"
MULTILINE=$(ls \
-1)
echo "${MULTILINE}"
Linux Directories in numeric format - i.e. drwxr-xr-x becomes 755
ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/) \
*2^(8-i));if(k)printf("%0o ",k);print}'
Linux Directories in numeric format - i.e. drwxr-xr-x becomes 755
ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/) \
*2^(8-i));if(k)printf("%0o ",k);print}'
Add oracle to the sudoers file :
//suggest a backup of this file
//suggest a backup of this file
chmod +w /etc/sudoers && echo "oracle ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && chmod -w /etc/sudoers
scp -r -p CNG_01_05_12 oracle@172.24.2.10:/u99/media/software/
where CNG_01_05_12 is a directory (no need for -r and -p when just a file, keep permissions and recursive)
Removing files with a space or strange characters
e.g. “Russ (2).zip”
ls –ali (use the first
number in the output which is the i-number then)
find . -inum
325454 -exec mv {} russ.tar \;
To show a tree listing in Unix Solaris :
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
To make life easy I tend to create an alias and use that.
If you run the ps command in Solaris it
truncates the output but
/usr/ucb/ps aww
Unix process start time
- ps -p <pid of that process> -o pid,cmd,start,time
- biff
story.
- ssh etc
Simple example.
Log onto Node 1 as user ‘grid’.
Run the following to create local (private and public) ssh keys:
ssh-keygen -t rsa
(opt against entering a passphrase)
Copy the public ssh key across to Node 2, into the ~/grid/.ssh directory. One way of doing this is via the following command:
ssh-copy-id grid@DB02
Confirm that the ‘grid’ user on Node 1 can connect to Node 2 with out being prompted for a password:
ssh DB02
- find but prune directory
find . -path ./dbpackages -prune -o -print
- lsof and alternative
#!/bin/bash
# Get the process which listens on port
# $1 is the port we are looking for
if [ $# -lt 1 ]
then
echo "Please provide a port number parameter for this script"
echo "e.g. $0 22"
exit
fi
echo "Greping for your port, please be patient (CTRL+C breaks) ... "
for i in `ls /proc`
do
pfiles $i | grep AF_INET | grep $1
if [ $? -eq 0 ]
then
echo Is owned by pid $i
fi
done
- When a 1000 means 1024
Talking to the apprentices at work and we ended up in a discussion about networks and storage on the Unix boxes and how things are measured. So to clear things up, IT borrowed naming conventions from the metric system. A kilobyte should actually be 1000 bytes as per the metric system but as computers use binary, everybody decided to use the power of 2 closest to 1000, which is 1024, thus 1 kilobyte(1 KB) meant 1024 bytes.
i..e
1 megabyte(MB) = 1024 kilobytes(KB) instead of 1000 kilobytes.
1 gigabyte(GB) = 1024 megabytes(MB) instead of 1000 megabytes.
Manufacturers stick to the standard decimal so errors grow as storage gets bigger.
For instance according to hardware manufacturers,
1 GB = 1000 MB = (1000 x 1000) KB = (1000 x 1000 x 1000) = 1000000000 bytes
in reality
1 GB = 1024 MB = (1024 x 1024) KB = (1024 x 1024 x 1024) = 1073741824 Bytes.
There is also confusion whether ‘b’ in Mb or Kb represented bits or bytes.
Hence in 2002, IEEE came up with the IEEE 1541-2002 standard concerning the use of prefixes for binary multiples of units of measurement related to digital electronics and computing.
So 1 GB = 1000 MB ( as used by OEM) but using the standard 1 GiB = 1024 MiB
Take note 10 Mbps is 10 Megabits per second and NOT 10 Megabytes per second(Mbps)
i.e. 10 Mbps = 1.25 MB; something broadband providers don't always make clear when advertising speeds.
In my experience, storage people tend to talk using 1024 and network people in the 1000s but always double check.
Find the amount of archiving you are using (run from the archive directory
#!/bin/bash
# check days
array=($(ls -la | grep 1_ | awk '{print $6 $7}'| uniq))
for ((i=0; i<${#array[@]}; i++));
do
mth=`echo ${array[$i]} | cut -c1-3`
day=`echo ${array[$i]} | cut -c4-5`
day2=`echo $day | awk '{printf "%2s",$1}'`
--need the day2 variable as unix pads the ls -al date output, see output below.
chk="$mth $day2"
echo -n "$chk "
# sum the files for the list of days
ls -la | grep "$chk" | grep 1_ | awk '{sum+=$5}END{print sum/1024/1024}'
done
# sum the total
echo -n "Total "
ls -la | grep 1_ | awk '{sum+=$5}END{print sum/1024/1024}'
# check days
array=($(ls -la | grep 1_ | awk '{print $6 $7}'| uniq))
for ((i=0; i<${#array[@]}; i++));
do
mth=`echo ${array[$i]} | cut -c1-3`
day=`echo ${array[$i]} | cut -c4-5`
day2=`echo $day | awk '{printf "%2s",$1}'`
--need the day2 variable as unix pads the ls -al date output, see output below.
chk="$mth $day2"
echo -n "$chk "
# sum the files for the list of days
ls -la | grep "$chk" | grep 1_ | awk '{sum+=$5}END{print sum/1024/1024}'
done
# sum the total
echo -n "Total "
ls -la | grep 1_ | awk '{sum+=$5}END{print sum/1024/1024}'
Feb 27 1794.99
Feb 28 5418.73
Feb 29 19742.7
Mar 1 20653.8
Mar 2 20185
Mar 3 16666
Mar 4 28250.2
Mar 5 31398.2
Mar 6 29603
Mar 7 26467.4
Mar 8 26008.9
Mar 9 29147.6
Mar 10 28755.8
Total 322010
Feb 28 5418.73
Feb 29 19742.7
Mar 1 20653.8
Mar 2 20185
Mar 3 16666
Mar 4 28250.2
Mar 5 31398.2
Mar 6 29603
Mar 7 26467.4
Mar 8 26008.9
Mar 9 29147.6
Mar 10 28755.8
Total 322010
[root@db03 arc]# pwd
/u02/backups/rman/db03/arc
-- quick aside if arch logs in ASM use something like :
select substr(FIRST_TIME, 1,9), count(FIRST_TIME) from V$ARCHIVED_LOG group by substr(FIRST_TIME, 1,9) order by 1
Show java home
[root@aspl03 /]# java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home'
java.home = /usr/java/jdk1.8.0_131/jre
[root@spl03 /]# /usr/java/jdk1.8.0_131/jre
---------------
Example shell script to loop through list of databases and do some output.
array=(`\ps -ef | egrep "(ora)_pmon_" | awk '{print $NF}' | sed 's/.*pmon_//'`)
for i in "${array[@]}" ; do
ORACLE_SID=${i}; export ORACLE_SID
echo "------------------------------------------------"
echo $ORACLE_SID
echo "------------------------------------------------"
sqlplus -s '/ as sysdba' << eof
set head off
set lines 200
col username format a40
col profile format a40
select username,profile from dba_users ;
eof
done
-----------------------------------
Using sed to create a directory name of the databases running with a logs subdirectory
mkdir -p `ps -ef | egrep "(ora)_pmon_" | awk '{print $NF}' | sed 's/.*pmon_//' | sed 's?$?/logs?'`
-----------------------------------
Quick notes re OEM ---
Once ASM and the OEM database up and running - listener too, you can then start Oracle OEM.
Had an issue where it was necessary to load "oracleasm init" to start the oracle stuff
check for "lsmod | grep oracle"
[oracle@usnyspmtaoem01 ~]$ lsmod | grep oracle
oracleasm 59173 1
Stop and start ASM instance - you may need to mount the disks too
If you don't the OEM database will complain - use srvctl to start the database.
When starting OEM use "emctl start oms" from the middleware home - NOT dbconsole as this will complain about missing directory
./emctl start oms
./emctl status oms
./emctl status oms -details
Currently OEM will start on IPV6 and should be IPV4 -- you can see this using "netstat -ntl" check for the port 7803 from status command above.
Disable IPV6
# sysctl -w net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.all.disable_ipv6 = 1
# sysctl -w net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6 = 1
Firewalld needs to be disabld etoo or web page will not appear
[root@usnyspmtaoem01 ~]# systemctl stop firewalld
[root@usnyspmtaoem01 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
- Quick script to test connections on scan listener
oracle_env(){
ORACLE_SID=umbapps1; export ORACLE_SID
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=/u01/app/oracle/product/12.2.0/dbhome; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin; export PATH
}
oracle_env
a=1
while [ $a -lt 20 ]
do
sqlplus -silent system/........@ora-scan:1521/ora_svc << EOF
set echo off
set heading off
set feedback off
select host_name from gv\$instance where instance_number=userenv('instance');
--SELECT UTL_INADDR.get_host_address from dual;
exit;
EOF
# if [ $a -eq 5 ]
# then
# break
# fi
a=`expr $a + 1`
sleep 1
done
Script to change something in a file - think this works!
check it first!!!
#!/bin/sh
for f in `find . -exec grep -il "whisky" -print`
do
sed 's/whisky/new_node/g' $f > ${f}.new
cp -p $f ${f}.prev
mv ${f}.new $f
done
- a wildcard works too so : sed s/localhost/oraserver01/g *_rmthost_mgrport.oby
Passing through display settings :
xauth add $(xauth -f ~oracle/.Xauthority list | tail -l)
No entry in oratab on AIX - to show Oracle Homes.
db01(oraoem)$ ps -ef | grep OEMAIX | grep pmon
oraoem 7930450 1 0 Oct 01 - 3:23 ora_pmon_OEMAIX
oraoem 7930450 1 0 Oct 01 - 3:23 ora_pmon_OEMAIX
db01(oraoem)$ ls -l /proc/7930450/cwd
lr-x------ 8 oraoem dba 0 Jan 12 17:09 /proc/7930450/cwd -> /u01/oracle/oraoem/product/12.1.0/oem13c/dbs/
lr-x------ 8 oraoem dba 0 Jan 12 17:09 /proc/7930450/cwd -> /u01/oracle/oraoem/product/12.1.0/oem13c/dbs/
If you have multiple dbs with no entry in oratab - something like to list all the homes:
#!/bin/ksh
COUNT=0
for i in `ps -ef | egrep "(ora)_pmon_" | awk '{print $2 " " $9}'`
do
let COUNT=COUNT+1;
if [ $(($COUNT % 2)) -eq 0 ]
then
printf $i | sed 's/.*pmon_//'
printf " \n"
else
ls -la /proc/`printf $i`/cwd | awk '{print $11}'
fi
done
(you need the odd / even as the $i reads the two values from the ps as one big array so odd is the home and the even is the sid - hope that makes sense)
Use this to list to run sql against multiple dbs:
## array="$(ps -ef | egrep "(ora)_pmon_" | awk '{print $NF}' | sed 's/.*pmon_//')"
for i in `ps -ef | egrep "(ora)_pmon_" | awk '{print $NF}' | sed 's/.*pmon_//'`
do
echo $i
ORAENV_ASK=NO
ORACLE_SID=$i
. oraenv > /dev/null
exit | sqlplus -s / as sysdba << eof
select * from global_name;
eof
done
As AIX does not have an ls -h option :
ls -l | awk '{$5=sprintf("%.9f GB", $5/1024^3)} 1'
An alias might be a good option for this.
Loop in AIX scripts - e.g. output some tables to html
#!/usr/bin/env bash
set -A array LEGAL_DD_DEEDS LEGAL_DD_NOTICES LEGAL_BUZZWORD
for i in "${array[@]}"
do
exit | sqlplus -silent legaldba/password as sysdba << EOF
set head off
set feedback off
set markup html on
spool $i.htm;
select * from LEGALDBA.$i;
spool off;
EOF
done
Tar a directory etc..set -A array LEGAL_DD_DEEDS LEGAL_DD_NOTICES LEGAL_BUZZWORD
for i in "${array[@]}"
do
exit | sqlplus -silent legaldba/password as sysdba << EOF
set head off
set feedback off
set markup html on
spool $i.htm;
select * from LEGALDBA.$i;
spool off;
EOF
done
tar -cvf - * | gzip -c > tarfile.tar.gz
gunzip on the tar file and use tar -tvf to list or tar -xvf tarfile.tar to extract.
Script to run "propeller" while waiting for something to finish
#!/bin/bash
# Do something and then sleep for 30 seconds
sleep 30 &
pid=$!
frames="\ | / -"
while kill -0 $pid 2&>1 > /dev/null;
do
for frame in $frames;
do
printf "\r$frame Waiting..."
sleep 0.5
done
done
printf "\n"
# Do something and then sleep for 30 seconds
sleep 30 &
pid=$!
frames="\ | / -"
while kill -0 $pid 2&>1 > /dev/null;
do
for frame in $frames;
do
printf "\r$frame Waiting..."
sleep 0.5
done
done
printf "\n"
To see the clear password on your wifi from the command prompt -
e.g. wifi n/w is vm244829
netsh wlan show profile vm244829 key=clear
Rename a group of files from e.g. .lst to .sql
for i in *.lst; do mv -- "$i" "${i%.lst}.sql"; done
List details for OCI instance -
curl -s http://169.254.169.254/opc/v1/instance/ | egrep -v "user_data|ssh_authorized_keys|timeCreated"
No comments:
Post a Comment