Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Thursday, 19 January 2017

Failed to link libclntsh.so.11.1 - Oracle DB and Linux

If you want to install Oracle DB on Linux machine and if you have this kind of errors:

Failed to link libclntsh.so.11.1

and

ld: cannot find -lxml11

Most probably you are trying to install 32bit Oracle installer on 64bit Linux.

You should use 64bit Oracle installer on 64bit Linux.


Also, see that you've exported LD_LIBRARY_PATH:

export LD_LIBRARY_PATH=$ORACLE_HOME/lib32

or

export LD_LIBRARY_PATH=$ORACLE_HOME/lib  (for 64bit build artifacts)


Friday, 9 January 2015

Java is not found on your Linux ? It might be the symlinks in /usr/bin that cause this...

It may happen that you have installed Java on your Linux system but it is not recognized as installed and existing.
Check out in /usr/bin directory these symbolic links:
/usr/bin/java
/usr/bin/javaw
They should be pointing to your Java installation folder's and the executables there. For example:

$ ll /usr/bin/java*
  java -> /etc/alternatives/java
  javaws -> /usr/java/latest/bin/javaws

In this case, the first symbolic link is not updated to the latest or default Java bin folder and this may be causing issues.
Change it to point to:
/usr/java/latest/bin/java

and the final result should be:

$ ll /usr/bin/java*
  java -> /usr/java/latest/bin/java
  javaws -> /usr/java/latest/bin/javaws

In my particular case, I wasn't able to find java on my remote Linux machine via SSH connection through PuTTY and adjusting the symlinks in /usr/bin fixed my problem.


Wednesday, 7 January 2015

Install multiple Java versions on a single Linux machine

It is often the case that you need to have multiple Java versions installed on a single machine. My own issue was that I needed Eclipse to be configured to use several versions of Java (toolbar menu Window -> Preferences -> Java -> Installed JREs) and in order to make them known to Eclipse I first need to have their installation folders.

On a RedHat Linux, once you have a Java installed, then installing a next one is not be possible, the OS will return error that Java was already installed. To workaround you need to do this.

1. Install your first java.
2. Rename its folder located in /usr/java/....
3. Delete the symbolic links "default" and "latest" in that same directory.
4. Uninstall Java from the Applications -> Add/Remove Software (under RedHat) or whichever way it is done on your Linux version.

5. Install the next java the usual way you do it.
This will create a new folder in /usr/java/  and will also create new "default" and "latest" symlinks in that same location.

Uninstalling Java will not remove its folder if you first rename it and then run uninstall, so you will keep it for further work. Switching to another active system java is just done by editing the symlinks "default" and "latest" pointing them to another java folder in /usr/java/...

You may also need to adjust the links in /etc/alternatives/java in order to make java work (be accessible) but this is subject for another post.

Saturday, 10 May 2014

More Linux shell commands

less  fileName => opens the file a page at a time.  SHIFT+G will move to the end of the file.


tail -3 fileName => open the file at the end showing just the last 3 lines that end with new line


mkdir  -p   a/b/c   => create empty directory structure in the current directory. If /a/b/c is used, then it will be created in the root of the system, if you have permissions.


rmdir -pv a/b/c  => remove the whole folder structure, starting from the bottom to top. The structure to delete must be explicitly described (a/b/c).
-p is the same option as above (parent)
-v is verbose output of all steps the command performs



ls -R folderName   => list recursively the content of the folder structure inside the folderName
ls -d  */     -> list only the directories in the current folder. * is all, / is just subfolders one level below.
                      To go deeper, add more */*/



u  user
g group
o other
chmod u+x file  -> set exec right to the owner (user)
chmod u=x file    -> set only exec right to the user (owner) of the file
chmod ugo=r  file   -> set only read rights to all three, user, group, others
chmod g=wx  file   -> set write and exec rights for the group
chmod a-rwx file   -> remove all three rights for all three kinds of users (owner,group,other)
chmod 000  file   -> same as above
chmod u+rwx,g+r,o+r  file  ->  set user all rights, group read and other read.
                                               No space around the comma.




Wednesday, 15 January 2014

df and du

'du' - Finding the size of a directory

$ du
Typing the above at the prompt gives you a list of directories that exist in the current directory along with their sizes. The last line of the output gives you the total size of the current directory including its subdirectories. The size given includes the sizes of the files and the directories that exist in the current directory as well as all of its subdirectories. Note that by default the sizes given are in kilobytes. 



$ du / -h --max-depth 1 list the same info in GB/MB for the root directory and go only one level in depth/down

$ du /home/deyan
The above command would give you the directory size of the directory /home/deyan


$ du -h
This command gives you a better output than the default one. The option '-h' stands for human readable format. So the sizes of the files / directories are this time suffixed with a 'k' if its kilobytes and 'M' if its Megabytes and 'G' if its Gigabytes.


$ du -ah

This command would display in its output, not only the directories but also all the files that are present in the current directory. Note that 'du' always counts all files and directories while giving the final size in the last line. But the '-a' displays the filenames along with the directory names in the output. '-h' is once again human readable format.


$ du -c
This gives you a grand total as the last line of the output. So if your directory occupies 30MB the last 2 lines of the output would be

30M .
30M total

The first line would be the default last line of the 'du' output indicating the total size of the directory and another line displaying the same size, followed by the string 'total'. This is helpful in case you this command along with the grep command to only display the final total size of a directory as shown below.


$ du -ch | grep total
This would have only one line in its output that displays the total size of the current directory including all the subdirectories.


$ du -s
This displays a summary of the directory size. It is the simplest way to know the total size of the current directory.


$ du -S
This would display the size of the current directory excluding the size of the subdirectories that exist within that directory. So it basically shows you the total size of all the files that exist in the current directory.

-

'df' - finding the disk free space / disk usage

$ df
Typing the above, outputs a table consisting of 6 columns. All the columns are very easy to understand. Remember that the 'Size', 'Used' and 'Avail' columns use kilobytes as the unit. The 'Use%' column shows the usage as a percentage which is also very useful.


$ df -h
Displays the same output as the previous command but the '-h' indicates human readable format. Hence instead of kilobytes as the unit the output would have 'M' for Megabytes and 'G' for Gigabytes.


Monday, 6 January 2014

Remove a symbolik link in Linux

Symbolik link is one that points to a file or directory, a kind of shortcut.
When it needs to be removed and you use the auto fill in of commands in the shell (TAB key) and you type rm then the name of the link, it will automatically add the name of the link and add a slash. This slash must be deleted in the command in order to be able to delete the symlink.

# correct way 
rm mySymLink
# incorrectly added slash
rm mySymLink/
 
The first one means you delete a file (which actually is the symlink) while the second is you want to delete a directory.
That's why you will get error you try to delete directory.
Also file permissions might be needed to be set up. 

Wednesday, 20 March 2013

Linux processes

To find a process

Use pgrep command. pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria to screen. For example display firefox process id:
# pgrep firefox
Sample outputs:
3356
 
or
# pidof firefox
3356  
 
Following command will list the process called sshd which is owned by a user called root:
$ pgrep -u root sshd


# ps 3356
Sample outputs:
PID   TTY  STAT   TIME   COMMAND
3356  ?    ..     ..     /path/to/executable
 
pstree shows running processes as a tree.  If a user name is specified, all process trees rooted at processes owned by that user are shown.
$ pstree
 
ps -u user  will show all processes of the user "user"
 $ ps -u user

Thursday, 21 February 2013

Find files

$ find /dir/to/search -name "fileName"

$ find   -name "fileName*"
this will search in the current directory and its sub-directories . It turned out that on my RedHat I had to use " " instead of single quotes ' '

$ find /dir/to/search -type d  -name "dirName"
search for a directory with name "dirName"

Wednesday, 20 February 2013

#!/bin/sh and its options -x and -e

Let’s look at an example.
#!/bin/sh
make
echo “Build exit code was $?”
What is the exit code of the script above?
It will be zero, always. Why?
Because the exit code of a script is the exit code of the last command and the echo command will succeed with very high probability.


The shell has a convenient option -e, which causes shell to stop running a script immediately when any command exits with non-zero exit code. This makes it easy to have Jenkins know when your script fails.

By the way, there’s also one more useful shell option you might want to know about, -x, which makes shell print every command it executes.

#!/bin/sh -xe   will exit if any command exits with non-zero exit code AND will print every command that is executed

Tuesday, 19 February 2013

Get information about Linux partitions

To Display Hard Disk Partition Size in Mega bytes or GB or TB:
$ df -H

To list all block devices, run:
# lsblk


NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    1   558G  0 disk
├─sda1   8:1    1   307M  0 part /boot
├─sda2   8:2    1   250G  0 part /webroot
├─sda3   8:3    1     6G  0 part [SWAP]
├─sda4   8:4    1     1K  0 part
└─sda5   8:5    1 301.7G  0 part /
sr0     11:0    1  1024M  0 rom



To determine the file system type or to find out what type of file systems currently mounted:

$ df -T

df command report filesystem disk space usage and if you pass -T option it will report filesystem type.

 $ mount

/dev/hdb1 on / type ext3 (rw,errors=remount-ro)
/dev/hdb2 on /home type ext3 (rw,errors=remount-ro)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
usbfs on /proc/bus/usb type usbfs (rw)
automount(pid3558) on /data type autofs (rw,fd=4,pgrp=3558,minproto=2,maxproto=4)
 
As you can see, second last column displays the file system type. For example first line [/dev/hdb1 on / type ext3 (rw,errors=remount-ro)] can be interpreted as follows:
  • /dev/hdb1 : Partition
  • / : File system
  • ext3 : File system type
  • (rw,errors=remount-ro) : Mount options
  
 
fdisk -l
Disk /dev/sda: 251.1 GB, 251059544064 bytes
255 heads, 63 sectors/track, 30522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0008fcd3
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          14      104448   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              14       13068   104857600   83  Linux
/dev/sda3           13068       13198     1048576   82  Linux swap / Solaris
/dev/sda4           13198       30523   139163648    5  Extended
/dev/sda5           13198       30523   139162624   83  Linux
 the star on /dev/sda1 shows that this is the bootable partition

fdisk -l | grep Disk

fdisk device   {fdisk /dev/sda1}
  
cfdisk 
 - DOS-based utility to manupulate partitions 


sfdisk -l /dev/sda

Wednesday, 14 November 2012

Get a file from a directory and assign it to variable

 At the bash shell prompt of Linux:

var=$(ls /home/user)

echo $var

this should echo the content of var, which is the listing of /home/user

You may want to assign to a variable the result of a find command:

var2=$(find /home/user -type f -name "MyFile*")

echo $var2

this should list the content of var2 - all files with name starting with "MyFile" in the /home/user path.

Get current directory path

CURRENTDIR=`pwd`
echo $CURRENTDIR
#will print the current directory

Note: note the ` char.

Functions in Linux

Function need to be declared FIRST before it is used.

functionName(){
    if [ "$1" == "1" ]; then
         echo "paramether is 1"
   else
       echo "parameter is not 1"
    fi
    if [ "$2" != "" ]; then
       echo "there is second parameter"
    fi
}

and call it like this:

functionName

OR pass an argument:

functionName 1

OR more arguments:

functionName 1 aString

Friday, 26 October 2012

Put file content into a variable

Linux

filetext=`cat printme`
echo "$filetext"

NOTE: note the ` char.
This will read the file printme and will assign its text to the variable filetext

"IF" on Linux shell script


VALID_PASSWORD="secret" #this is our password.

echo "Please enter the password:"
read PASSWORD

if [ "$PASSWORD" == "$VALID_PASSWORD" ]; then
 echo "You have access!"
else
 echo "ACCESS DENIED!"
fi
 
 
Comparisons:
-eqequal to
-nenot equal to
-ltless than
-leless than or equal to
-gtgreater than
-gegreater than or equal to

File Operations:
-sfile exists and is not empty
-ffile exists and is not a directory
-ddirectory exists
-xfile is executable
-wfile is writable
-rfile is readable
-ntests to see if the argument is non empty   

X=""
# -n tests to see if the argument is non empty
if [ -n $X ]; then  
 echo "the variable X is not the empty string"
fi

if [ "$AGE" -lt 20 ] || [ "$AGE" -ge 50 ]; then
 echo "Sorry, you are out of the age range."
elif [ "$AGE" -ge 20 ] && [ "$AGE" -lt 30 ]; then
 echo "You are in your 20s"
fi 

if [[ $count -gt 0  &&  $somevar != $var ]]; then
...no brackets inside, only double [[  ]]
fi



if [ $count -gt 0 ] && [ $somevar != $var ]; then
...do something
fi


Wednesday, 24 October 2012

File transfer between Linux machines - scp

To copy a file from another machine:

# scp username@123.123.123.123:/get/this/file   /put/it/here

to copy a directory
# scp -r username@123.123.123.123:/get/this/file   /put/it/here
-r
Recursive, so it copies the contents of the source-file (directory in this case) recursively

Unzip expects -d /path/to/unzip/dir

Shell command "unzip" turned out to require paramether -d /path/to/unzip/dir.
Otherwise it will presume you want to unzip it in the current directory.

So the format should be:

unzip /my/zipfile.zip -d /path/to/unzip

I had tried

unzip /my/zipfile.zip  /path/to/unzip  and it did not work, so paramether -d was required.

Moving file between Windows and Linux change the EOL characters

I needed to commit a shell script to the Jenkins CI.
So first moved the script from the Linux machine to my local working copy (on Windows) and then commited it to the SVN. It turned out I could not execute the script after checkout on a Linux machine and reason was the the file transfer from Linux to Windows changed the EOL (End Of Line) endings to Windows format (CR/LF) replacing the LF format of UNIX.

To fix it, open script in Notepad++ -> Edit -> EOL conversion -> UNIX format

Then commit and should work after being checkout on Linux machine.

Also, I had tried to change encodings to whatever possible in Notepad++ and left it to Unicode-8. Again, that was a reason script to not be possible to run on Linux. So, change Encoding to "ASCII" by "Convert to ASCII"