Avoid duplicates in $PATH

By: | Comments: No Comments

Posted in categories: Computer Tips, Work related

Linux search /etc/profile.d and ~/.bashrc, ~/.bash_profile for system and user defined environmental variables. One of the most manipulated variable is $PATH. You can see this by running

$ echo $PATH

In most cases, when a new 3rd party software is installed, and you want it to be in your default executable search path, you insert a line like

export PATH=$PATH:/where/your/new_executables

in your ~/.bash_profile or in a file in /etc/profile.d if you are a system administrator. This appends a new search path onto the existing one.

However, if you launch another terminal, a shell, etc., all these scripts are loaded again and you got duplicated entries in $PATH.

This looks harmless and does not affect system performance in most cases since bash looks for the first available executable in the search path and ignore all later appended paths.

However, if you are running some scripts that loop into multiple layers of shells, this could cause the $PATH string overflow and disrupt your script. Also for cosmetic reason, a very long $PATH filled with duplicates are ugly.

To not generate duplicates, we can do:

NEWPATH=/where/your/new_executables 
if [ -d "$NEWPATH" ] && [[ ":$PATH:" != *":$NEWPATH:"* ]]; then
    PATH="${PATH:+"$PATH:"}$NEWPATH"
fi
export PATH;

for appending or

NEWPATH=/where/your/new_executables 
if [ -d "$NEWPATH" ] && [[ ":$PATH:" != *":$NEWPATH:"* ]]; then
    PATH="$NEWPATH${PATH:+":$PATH"}"
fi
export PATH;

for prepending, instead of the

export PATH=$PATH:/where/your/new_executables

way. This, will prevent generating duplicated entries in $PATH since it will only add in a new entry when the new entry is not found in the existing environmental variable.

Installing Lapack in CentOS 7-8

By: | Comments: No Comments

Posted in categories: Computer Tips, Work related

For CentOS7,

ccmake -DCMAKE_INSTALL_PREFIX=/usr/local/lapack -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=ON -DLAPACKE=ON ..

Then make, make install will get you a working version of liblapacke.so

The current version 3.8.0 source has bugs that prevent the .so to work properly. Version 3.7.1 is the best to do.

For CentOS8, the Fedora 29 version of Lapack works by dnf install.

Ganglia cannot display cluster view with certain version of php

By: | Comments: No Comments

Posted in categories: Computer Tips, Work related

This is related with a version compatibility issue.

nano +26 /usr/share/ganglia/cluster_view.php

change

$context_metrics = “”;

to

$context_metrics = array();

will do the job.

kill zombies

By: | Comments: No Comments

Posted in categories: Computer Tips, Work related

A zombie is already dead, so you cannot kill it. To clean up a zombie, it must be waited on by its parent, so killing the parent should work to eliminate the zombie.

An example of how you might send a signal to every process that is the parent of a zombie (note that this is extremely crude and might kill processes that you do not intend. I do not recommend using this sort of sledge hammer):

kill $(ps -A -ostat,ppid | awk ‘/[zZ]/ && !a[$2]++ {print $2}’)

Using lightdm + slick greeter

By: | Comments: No Comments

Posted in categories: Computer Tips, Work related

Linux default greeters list user names on log in screen. This is sort of a security risk. Using lightdm + slick greeter can avoid this, rendering it back to the key-in username type.

To do so,

dnf install lightdm slick-greeter

systemctl stop gdm (or whatever dm you are using)

systemctl disable gdm

edit /etc/lightdm/lightdm,conf, change greeter-session to

greeter-session=slick-greeter

systemctl enable lighdm

if masked, systemctl unmask lightdm first

then reboot.

Using MESA to render OpenGL > 1.4 remotely

By: | Comments: No Comments

Posted in categories: Computer Tips, Work related

When you are working on a remote server through nomachine or vnc, and there is no video card on the remote server that supports OpenGL > 1.4, the MESA in default render OpenGL version 1.4. This will cause the application to fail even if they do not really need to raise a GUI.

Here is a way to force MESA to report its GL version to 3.3 such that certain applications will generate correct result without terminate while sensing a too low GL version:

Put the following environment string in front of your command:

MESA_GL_VERSION_OVERRIDE=3.3 your_command

This method does not work through ssh x-tunneling since in the latter case the x-server tends to take the GL command.

If you want this to go through an x-server that also uses mesa, you will need to put on the MESA_GL_VERSION_OVERRIDE=3.3 before your ssh command too.

Using Nomachine through ssh tunner

By: | Comments: No Comments

Posted in categories: Computer Tips, Work related

Nomachine uses port 4000, however, the server may not have that port opened to your local IP. However, as long as you can ssh the server, you can use the following ssh tunnel to use Nomachine – securely and fast:

  1. From a ssh client, do: ssh -L <port>:localhost:4000 -N -f <username>@<nomachine_server>
  2. From your nomachine client, set host localhost, port of the port number as <port>

Here you go.

Scponly cannot chroot

By: | Comments: No Comments

Posted in categories: Computer Tips, Work related

Scponly from CentOS 7 cannot chroot. Problem is that /sbin/scponlyc does not have corrent SUID. Do a

chmod 4755 /sbin/scponlyc

resolves it.

Seagate NAS make no_root_squash

By: | Comments: No Comments

Posted in categories: Uncategorized

Seagate NAS create NFS shares as root_squash. This makes is inconvenient to use it as linux backup device. By remounting / as rw, editing /usr/lib/python2.7/site-packages/unicorn/sharing/nfs.py, change root_squash to no_root_squash, reboot, problem saved.

Ganglia under php7

By: | Comments: No Comments

Posted in categories: Computer Tips, Work related

Ganglia web interface cannot display charts in CentOS7, if php is updated to version 7.

This is because /usr/share/ganglia/cluster_view.php in line 34, $context_metrics[] was originally initialized as “”, in line 26.

If changing line 26 to

$context_metrics = [];

The problem is fixed.