cd $ORACLE_GG tree -L 2 --noreport $(ls -d dir* | grep -v '^dirdat$')
Minimalistic Oracle contains a collection of practical examples from my encounters with Oracle technologies. When relevant, I also write about other technologies, like Linux or PostgreSQL. Many of the posts starts with "how to" since they derive directly from my own personal experience. My goal is to provide simple examples, so that they can be easily adapted to other situations.
Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts
Wednesday, July 9, 2025
How to list all subdirectories and exclude certain subdirectories in a tree-like fashion
In this example I want to see all subdirectories that starts with "dir", but also to exclude the directory "dirdat":
ls -d dir*: lists all dir* entries (only directories if they match)
grep -v '^dirdat$': removes dirdat from the list
$(...): expands the filtered list as arguments to tree
Monday, December 2, 2024
How to use rsync between two servers
For example, to syncronize two servers so they get identical file structures:
The --delete flag in rsync ensures that files in the destination directory (ebsuser@$target:/u01/app) that are not present in the source directory (/u01/app/inst) are deleted. This helps keep the destination directory synchronized with the source directory.
- Source server: server1.oric.no
- Destination server: server2.oric.no
- Execute as: root
target=server2.oric.no && rsync -vaz --delete /u01/app/myfiles ebsuser@$target:/u01/appThis will sync the entire "/u01/app/myfiles" folder + all subfolders.
The --delete flag in rsync ensures that files in the destination directory (ebsuser@$target:/u01/app) that are not present in the source directory (/u01/app/inst) are deleted. This helps keep the destination directory synchronized with the source directory.
Thursday, July 27, 2023
How to list the contents of a folder in a tree-like fashion in Linux
Use the tree command:
cd /sw/oracle/admin tree -L 2 . ├── cdb │ ├── adump │ ├── dpdump │ ├── log │ ├── pfile │ └── xdb_wallet ├── sales │ ├── adump │ ├── dpdump │ ├── pfile │ ├── sql │ └── xdb_wallet └── hr ├── adump ├── dpdump ├── log ├── pfile ├── scripts ├── sql └── xdb_wallet 20 directories, 0 filesThe -L flag indicates the number of levels you want to display. In my case, if I change the value from 2 to 3, I get the output below instead (abbreviated):
. ├── cdb │ ├── adump │ │ ├── FE78BD1F8E6730CDE0536709D10AC9C0 │ │ └── FE7BD04D2DFBE569E0536709D10A3AF0 │ ├── dpdump │ │ ├── dp.log │ │ ├── FE78BD1F8E6730CDE0536709D10AC9C0 │ │ ├── FE7AF28B415262F7E0536709D10A8B2E │ │ └── FE7BD04D2DFBE569E0536709D10A3AF0 │ ├── log │ │ ├── 2023-07-11_cdb.2431565 │ │ ├── 2023-07-12_cdb.2489915 │ │ ├── 2023-07-12_cdb.2576176 ├── sales │ ├── adump │ ├── dpdump │ │ └── dp.log │ ├── pfile │ │ └── init.ora.5192023145034 │ ├── sql │ │ ├── analyze_sales.sh │ │ ├── cfgtoollogs │ │ ├── config_sales.txt │ │ ├── cre_db.sh │ │ └── deploy_sales.sh 26 directories, 181 filesThe command is not installed by default but is avaible both for RHEL / CentOS / Fedora Linux as well as Debian based Linux distributions like Ubuntu.
Thursday, June 15, 2023
How to list the content of a folder and get total size summary of the parent folder at the end
To list the size of all folders and get a summery at the end, use the --max-depth=1 switch with the du command.
In the listing below, I am following the examples of a recent blog post by Mike Dietrich, to measure the size of the subfolders in the .patch_storage folder, which is maintained by OPatch in case the DBA needs to rollback the patches later.
In the listing below, I am following the examples of a recent blog post by Mike Dietrich, to measure the size of the subfolders in the .patch_storage folder, which is maintained by OPatch in case the DBA needs to rollback the patches later.
cd $ORACLE_HOME/.patch_storage du -h --max-depth=1 100K ./29585399_Apr_9_2019_19_12_47 284K ./NApply 4.0K ./oracle-home-1681903491076105 434M ./34786990_Dec_6_2022_13_24_50 20K ./NRollback 436M ./35050341_Mar_17_2023_04_11_10 2.0G ./35042068_Apr_6_2023_15_25_04 91M ./backup_delete_inactive 2.9G .
Friday, April 21, 2023
How to get verbose output in a call to mailx
Use the -vvv flag to debug your call to mailx:
root # echo "Test message" | mailx -S smtp="smtp.oric.no" -vvv -s "$(hostname) is up" monitoring@oric.no
Sunday, February 19, 2023
How to identified active files/executables when using opatch to deinstall software
During a opatch rollback operation, we saw the following error message in the opatch logfile:
Some processes are still using the /sw/oracle/product/19.18/lib/libclntsh.so.19.1.
Use the fuser utility with verbose output to find the process:
There were two open processes using the file libclntsh.so.19.1: 1. the Golden Gate Manager 2. a utility called prometheus_oracle_exporter
Solution:
[Feb 19, 2023 2:29:51 PM] [INFO] Prerequisite check "CheckActiveFilesAndExecutables" failed. The details are: Following active files/executables/libs are used by ORACLE_HOME :/sw/oracle/product/19.18 /sw/oracle/product/19.18/lib/libclntsh.so.19.1Reason:
Some processes are still using the /sw/oracle/product/19.18/lib/libclntsh.so.19.1.
Use the fuser utility with verbose output to find the process:
fuser -v /sw/oracle/product/19.18/lib/libclntsh.so.19.1 USER PID ACCESS COMMAND /sw/oracle/product/19.18/lib/libclntsh.so.19.1: oracle 48439 ....m prometheus_orac oracle 595787 ....m ggsci
There were two open processes using the file libclntsh.so.19.1: 1. the Golden Gate Manager 2. a utility called prometheus_oracle_exporter
Solution:
log in as the Golden Gate software owner ggsci --> info all --> list all processes stop mgr !One of two processes quit its handler on the file:
fuser -v /sw/oracle/product/19.18/lib/libclntsh.so.19.1 USER PID ACCESS COMMAND /sw/oracle/product/19.18/lib/libclntsh.so.19.1: oracle 48439 ....m prometheus_oracFor the prometheus agent, we simply kill the agent, and the output from fuser now reveals that no file handlers are open:
kill 48439 fuser -v /sw/oracle/product/19.18/lib/libclntsh.so.19.1
Saturday, February 18, 2023
How to prevent sed to destroy your symlinks
Because of EBS, we have a subdirectory in our $TNS_ADMIN which has the following name
PDB1_test1.oric.noIn other words, the files listener.ora, sqlnet.ora and tnsnames.ora are symlinks pointing to this subdirectory:
# ls -altr lrwxrwxrwx 1 oracle dba 34 Feb 10 13:29 sqlnet.ora -> PDB1_test1.oric.no/sqlnet.ora lrwxrwxrwx 1 oracle dba 36 Feb 10 13:29 tnsnames.ora -> PDB1_test1.oric.no/tnsnames.ora lrwxrwxrwx 1 oracle dba 36 Feb 18 12:17 listener.ora -> PDB1_test1.oric.no/listener.ora drwxr-xr-x 2 oracle dba 4096 Feb 18 12:18 PDB1_test1.oric.no drwxr-xr-x 5 oracle dba 4096 Feb 18 12:19 .If you are to exchange a string in these files, for example when switching to a new version of the Oracle software, make sure you use the directive --follow-symlinks to preserve your symlinks:
export PRE_ORACLE_VERSION=19.17 export NEW_ORACLE_VERSION=19.18 cd $TNS_ADMIN sed --follow-symlinks -i "s/$PRE_ORACLE_VERSION/$NEW_ORACLE_VERSION/g" listener.oraIf you don't, the listener.ora will be placed directly in $TNS_ADMIN, and the symlinks will be dropped.
Tuesday, February 14, 2023
Error fetching the value from a shell script executed by root, when doing "su - oracle"
Problem:
Inside a new bash shell session, executed as user "oracle", like this:
I tried all possible variants (I thought), but was still unable to get my shell script to hold the value in a variable and use it locally within the oracle user session.
Solution:
Use backslash around the entire command, marked in yellow below:
Credit goes to an experienced and clever colleague of mine, who shall remain nameless unless he actively wants his name listed on my blog ;-)
Inside a new bash shell session, executed as user "oracle", like this:
su - oracle <<! instructions here !I was not able to save the value of a string extracted from an xml file in a session variable.
I tried all possible variants (I thought), but was still unable to get my shell script to hold the value in a variable and use it locally within the oracle user session.
Solution:
Use backslash around the entire command, marked in yellow below:
su - oracle <<! export CNTXT_FILE_PERL_VERSION=\`grep PERL5LIB \$CONTEXT_FILE | awk -F "site_perl/" '{print \$2}' | cut -f 1 -d":"\` !
Credit goes to an experienced and clever colleague of mine, who shall remain nameless unless he actively wants his name listed on my blog ;-)
Friday, January 6, 2023
How to solve script error $'\r': command not found syntax error: unexpected end of file
when trying to execute a script from root, like the following:
You have windows-style formatting in your file
Solution:
su - oracle -c "/tmp/set_params.sh"You may see errors like the following:
set_params.sh: line 6: $'\r': command not found set_params.sh: line 42: syntax error: unexpected end of fileRoot cause:
You have windows-style formatting in your file
Solution:
dos2unix set_params.sh dos2unix: converting file flexpod_params.sh to Unix format...When executed again, the above errors should be gone!
Wednesday, November 16, 2022
How to log entire output from a shell script
I have recently used exec to send all output from a bash script to a designated logfile.
For example, if you have a complex script which performs multiple tasks and even execute tasks under a different user along the way, all the output will go into the global logfile indicated by the $GLOGFILE variable:
Good sources:
Linuxfordevices.com
Geeksforgeeks.org
For example, if you have a complex script which performs multiple tasks and even execute tasks under a different user along the way, all the output will go into the global logfile indicated by the $GLOGFILE variable:
#!/bin/bash
export SCRIPT_NAME=`basename $0`
export TS=`date +\%m.\%d.\%y\_%H_%M_%S`
export GLOGFILE=/u01/mylogfile_${TS}.log
touch ${GLOGFILE}
chmod 666 ${GLOGFILE}
exec 1> ${GLOGFILE} 2>&1
echo "Starting job at " `date`
your shell instructions here
echo "Ending job at " `date`
exit
Good sources:
Tuesday, July 5, 2022
How to list all nfs mountpoints
findmnt -t nfs TARGET SOURCE FSTYPE OPTIONS /u01 pzl2ora1:/Oracle/software/pzh0oric/u01 nfs rw,nodiratime,relatime,vers=3,rsize=65536,wsize=65536,namlen=255,acregmin=300,acregmax=300,acdirmin=300,ac /u02 pzl2ora1:/Oracle/pzh0oric/u02 nfs rw,nodiratime,relatime,vers=3,rsize=65536,wsize=65536,namlen=255,acregmin=300,acregmax=300,acdirmin=300,ac /u03 pzl2ora1:/Oracle/pzh0oric/u03 nfs rw,nodiratime,relatime,vers=3,rsize=65536,wsize=65536,namlen=255,acregmin=300,acregmax=300,acdirmin=300,ac /u04 pzl2ora1:/Oracle/pzh0oric/u04 nfs rw,nodiratime,relatime,vers=3,rsize=65536,wsize=65536,namlen=255,acregmin=300,acregmax=300,acdirmin=300,ac
Tuesday, December 21, 2021
How to work around error [INS-08101] Unexpected error while executing the action at state: ‘supportedOSCheck’
Thanks so much to Martin Berger for his blog post showing how to work around an error that shows up when you attempt to install Oracle 19c software on a RHEL8 distribution.
In my case, the only thing I had to do was to add another environmental variable:
I wanted to install Oracle software on a RH8.5 Linux server:
This is the error I received:cat /etc/redhat-releaseRed Hat Enterprise Linux release 8.5 (Ootpa)
In my case, the only thing I had to do was to add another environmental variable:
export CV_ASSUME_DISTID=OEL7.8Execute the installer again and you will see a different screen:
./runInstaller
Friday, December 4, 2020
How to view the contens of a zip file without extracting it
Method 1:
Method 2:
zip -sf myzipfile.zip
zipinfo myzipfile.zip
Thursday, October 15, 2020
How to select a specific line number using awk
The file clonetext.txt contains:
You would like to get the name of the volume, which is the 4th word on the 3rd line of the file. When grepping for the keyword "Clone" all lines are returned:
Clone Volume: true Clone Parent server Name: myserver1-cluster49 SnapClone Parent Volume: myvolume_mirror1
You would like to get the name of the volume, which is the 4th word on the 3rd line of the file. When grepping for the keyword "Clone" all lines are returned:
cat clonetext.txt | grep Clone Clone Volume: true Clone Parent server Name: myserver1-cluster49 SnapClone Parent Volume: myvolume_mirror1Grepping for the 4th column helps, but you still get two rows, not just the single one you're interested in:
oracle@oric-db01:[mydb01]# cat clonetext.txt | grep Clone | awk -F' ' '{print $4}' Name: myvolume_mirror1Adding the NR flag to your command solves the problem:
cat clonetext.txt | grep Clone | awk -F' ' 'NR==3 {print $4}'
myvolume_mirror1
Monday, August 3, 2020
How to find offending process when getting error umount.nfs: /data1: device is busy
As root, use lsof ("list open files"):
[root@myserver /home/oracle]# lsof | grep '/data1' extract 14041 oracle 25r REG 0,23 2896 1235955379 /data1/goldengate/dirdat/et000000127 (storage1:/Oracle/myserver/data1)You will see a list of processes. Terminate these with the kill-command:
kill 13859 14041After this is done, you can unmount the nfs file system:
umount -f /data1
Tuesday, February 25, 2020
How to debug an ssh connection
ssh -X -v myserver.mydomain.com
You can also use -vv and -vvv for more detailed debug information.
Sunday, May 26, 2019
How to display Linux kernel and version information on debian platforms
Use the lsb (Linux Standard Base) utility:
or view the file /etc/os-release:
lsb_release -aOutput:
No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04.1 LTS Release: 18.04 Codename: bionicReplace the -a switch with the -d switch to limit the output to the version only.
or view the file /etc/os-release:
cat /etc/os-release:
NAME="Ubuntu" VERSION="18.04.1 LTS (Bionic Beaver)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 18.04.1 LTS" VERSION_ID="18.04" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=bionic UBUNTU_CODENAME=bionic
Subscribe to:
Posts (Atom)