Thursday, May 19, 2016

Oracle Linux - Clone file permissions with chmod

Every now and then file permissions under Linux can be tricky. in some cases a wrong file permission can make it happen that things do not work they way you would expect them. Also I found that a lot of people find it challenging to set the correct file permissions using the command line under Linux. A way to make life more easy in some cases is to use the option to "clone" file permissions with a single command.

For example, if you have created some addons to a tool running on an Oracle Linux system and you want to the addon file to have the same permissions as another file you can use the --reference option from the chmod command.

As an example we have two .jar files:

[root@localhost ~]# ls -l *.jar
-rwxr-xr-x. 1 root root 88 May 19 10:48 addonExecution.jar
-rw-r--r--. 1 root root 11 May 19 10:48 executionLib.jar

We want to make sure that the addonExecution.jar has exactly the same permissions as the executionLib.jar file. We can do this by specifying the desired stated in a chmod command, we can also use the --reference option as shown below:

[root@localhost ~]# chmod --reference=executionLib.jar addonExecution.jar

This will make sure that the addonExecution.jar file now has exactly the same permissions as the file used as a reference.

[root@localhost ~]# ls -l *.jar
-rw-r--r--. 1 root root 88 May 19 10:48 addonExecution.jar
-rw-r--r--. 1 root root 11 May 19 10:48 executionLib.jar

Another use case example of this is that you can use it in a bash script where you might not be sure what the permissions should be for a certain file and only know that they always need to be the same as a specified other file. By using the --reference option you do not explicitly need to know the permissions during the creation of the bash script, you only need to know which file can be used as a reference. 

Oracle Linux - remove duplicate lines with awk

Sometimes you want to clean data quickly and remove all duplicate lines that are present in the file. For example a raw output from a system that is "dumped" on your Linux file system needs to be cleaned before you use it as input into another system. You can write some fancy code to do so, you can also use a very simple and straight forward solution by using awk on your Oracle Linux bash shell.

In the below example we have a file (the data with the duplicate lines) called rawdata.txt and we want to make a clean file called cleandata.txt. The example awk command can be used to read rawdata.txt and write the clean data to the file cleandata.txt

awk '!seen[$0]++' rawdata.txt >> cleandata.txt

The command itself is a very quick and dirty solution, most likely you want to use this in a wider script that is cleaning your data in a more sophisticated manner. 

Sunday, May 15, 2016

Oracle Linux Name Service Switch libraries

When scripting a bash solution which needs to check if a user is existing on your Oracle Linux instance you have a couple of options. The most known solution is to check if the username is present in the /etc/passwd file. You can simply do a cat of this file and using grep and wc command to make it more usable in your script. An example of this could be for example the command below which will give you the number of times that “apache” is mentioned in the file. Do remember, we assume this is the user apache and this is not very reliable in reality.

cat /etc/passwd | grep apache | wc –l

Another solution is making use of getent which is not that well known as the above example. The getent command displays entries from databases supported by the Name Service Switch libraries. An example of this is shown below:

[root@dev1 ~]# getent passwd apache
apache:x:48:48:Apache:/var/www:/sbin/nologin
[root@dev1 ~]#

Where in case the user is not existing the command will provide no output:

[root@dev1 ~]# getent passwd apache222
[root@dev1 ~]#

Using a wc –l on getent will provide you a more pure answer opposed to a wc –l on a cat from the passwd file. As stated; The getent command displays entries from databases supported by the Name Service Switch libraries. To understand this in a bit more detail and understand what databases are that are supported by the Name Service Switch libraries you can check the configuration file. Under Oracle Linux (and most other Linux distributions) this can be found at /etc/nsswitch.conf .  An example of a standard nsswitch.conf file is shown below. As you can see a lot more is supported by the Name Service Switch libraries and not only passwd.

#
# /etc/nsswitch.conf
#
# An example Name Service Switch config file. This file should be
# sorted with the most-used services at the beginning.
#
# The entry '[NOTFOUND=return]' means that the search for an
# entry should stop if the search in the previous entry turned
# up nothing. Note that if the search failed due to some other reason
# (like no NIS server responding) then the search continues with the
# next entry.
#
# Valid entries include:
#
#       nisplus                 Use NIS+ (NIS version 3)
#       nis                     Use NIS (NIS version 2), also called YP
#       dns                     Use DNS (Domain Name Service)
#       files                   Use the local files
#       db                      Use the local database (.db) files
#       compat                  Use NIS on compat mode
#       hesiod                  Use Hesiod for user lookups
#       [NOTFOUND=return]       Stop searching if not found so far
#

# To use db, put the "db" in front of "files" for entries you want to be
# looked up first in the databases
#
# Example:
#passwd:    db files nisplus nis
#shadow:    db files nisplus nis
#group:     db files nisplus nis

passwd:     files
shadow:     files
group:      files

#hosts:     db files nisplus nis dns
hosts:      files dns

# Example - obey only what nisplus tells us...
#services:   nisplus [NOTFOUND=return] files
#networks:   nisplus [NOTFOUND=return] files
#protocols:  nisplus [NOTFOUND=return] files
#rpc:        nisplus [NOTFOUND=return] files
#ethers:     nisplus [NOTFOUND=return] files
#netmasks:   nisplus [NOTFOUND=return] files

bootparams: nisplus [NOTFOUND=return] files

ethers:     files
netmasks:   files
networks:   files
protocols:  files
rpc:        files
services:   files

netgroup:   nisplus

publickey:  nisplus

automount:  files nisplus
aliases:    files nisplus

Wednesday, May 11, 2016

Oracle Linux addons channel

When working with Oracle Linux and using the Oracle Linux YUM repository you might be missing out. It is worth while checking which channels are being activated for YUM as not all channels are active by default after an installation or might have been disabled by a template installation.

Something I do see commonly is that administrators who create Oracle Linux templates do disable a lot of the YUM channels. If you receive a template based installation in a private cloud setup it is good practice to first check which channels are activated and which have been disabled. If some of the channels, for example the addons channel, are disabled you might be missing out on a lot of things and find yourself in a “dependency hell”

Rather than trying to resolve this manually it is good to check the channel settings in /etc/yum/repos.d/* normally this will be /etc/yum.repos.d/public-yum-ol6.repo for OL6 machines.

A default installation will state enabled=0 for the public_ol6_adddons channel. To enable this you will have to state enabled=1

Even though it might sounds like a minor change, it is commonly overlooked in first instance. Additional channels are available for Oracle Linux from the public Oracle YUM server which might be of interest to administrators to enable.

Tuesday, May 10, 2016

Oracle Linux pre-install RPM for EBS

When deploying Oracle software on a Oracle Linux (or any other Linux distribution) you will have to set a number of pre-requisites. In some cases you need to set certain kernel parameters and ensure you have specific packages installed on your machine.

For the Oracle database there is already for a long time a way of doing this by installing a specific RPM. As this is providing a great way of preparing your environment for the software installation Oracle is also providing a similar mechanism for preparing your environment for the installation of Oracle e-Business suite.

You can install a pre-install RPM for Oracle e-Business Suite 12.1 and 12.2 which you can fetch from the addons channel at ULN. A best practice for creating a new Oracle Linux environment to run Oracle e-Business Suite is to do a minimal installation of Oracle Linux and install the pre-install RPM on top of this. Reason for this is that you will not have unneeded packages and functionality which might cause hindrance at a later stage.

  • In essence the pre-install RPM will undertake the following tasks:
  • Downloading and installing all software package versions and dependencies required for installing E-Business Suite R12 (12.1, 12.2)
  • Creating the users oracle and applmgr for use as owners of the database and application tiers respectively, while setting hard and soft shell resource limits
  • Updating kernel parameters in /etc/sysctl.conf to recommended values
  • Sets DNS resolver parameters in /etc/resolv.conf to minimum recommended values
  • Sets 'numa=off' in the kernel in the kernel commandline
  • Disables 'Transparent Huge Pages (THP)' if enabled 



For more information on the pre-install RPM’s please refer to the following notes on My Oracle Support: 761566.1 & 1330701.1