Linux performance problems and some helpful commands

On one of our RHEL systems we had an issue with high load. In some cases our java application crashed.

The following command helped us to find the reason (in our case it was the limit of processes per user).

vmstat -SM -t 10 10
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ ---timestamp---
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0  12448    562  36934    0    0     0     3    3    2  0  0 100  0  0       2017-04-11 17:20:38 CEST
 0  0      0  12448    562  36934    0    0     0     4 1059 1975  0  0 100  0  0       2017-04-11 17:20:48 CEST
 0  0      0  12448    562  36934    0    0     0     3 1158 2038  0  0 100  0  0       2017-04-11 17:20:58 CEST

with ulimit we could see, that the „max user processes“ was set to a very low level. That was the reason why our application crashed (java could not open addidtional threads).

ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 257569
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1000000
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1200
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited


# show load, currently running threas/process and ?
cat /proc/loadavg
0.00 0.00 0.00 1/1570 14415


# with this command you can count the number of processes (limited by "max user process" of ulimits command)
ps -elfT | grep philipp | wc -l

Search LDAP Entries with ldapsearch on Linux/Unix

RedHat ldapsearch Documentation

ldapsearch -D "CN=<MyUser>,OU=S,OU=Useraccounts,DC=de,DC=<COMPANY>,DC=com" -w "PASSWORD" -b "DC=<MyCompany>,DC=com" 
   -s sub "(& (objectClass=user) (name=TestUser1))" -h "" -p "3268" telephonenumber name department

# Result:
# extended LDIF
# LDAPv3
# base <DC=<MyCompany>,DC=com> with scope subtree
# filter: (& (objectClass=user) (name=TestUser1))
# requesting: telephonenumber name department

# TestUser, M, Useraccounts, XX,
dn: CN=TestUser1,OU=M,OU=Useraccounts,OU=XX,DC=emea,DC=MyCompany,DC=com
department: <HIDDEN>
name: TestUser1
telephonenumber : 0711-XXXXXXXXX

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1

-D     Username (BaseDN) that is used to connect to ldap
-w     Password to connect to ldap
-b     Specifies the starting point for the search
-s     Specifies the scope of the search
sub  search also in subtree
(& (objectClass=user) (name=mcp8wz)) = filter for objects with objectClass=user and where attribute „name“ = mcp8wz
-h     hostname of LDAP Server
-p     Port of LDAP Server
at the end of the command you can add all attributes you would like to fetch from LDAP. Leave empty to retrieve all information


Remove last lines from file with shell, bash, csh, zsh

To remove the last X lines of a file, the easiest way is to use head combined with wc -l

# get the output of wc -l (which counts the lines of a file), parse them to a number 
# and extract 3 (the number of lines you want to remove)
philipp@Host% set CMD1="expr `cat longFile.csv | wc -l` - 3"

# now remove last 3 lines by using head and redirect them to your file
philipp@Host% head -n  `$CMD1` Segment5_Contexts.csv > shortFile.csv

Connection to remote networks with (tox-) socks and proxychains

To connect from your local workstation to a remote network through socks proxies you can use (tox-) socks.

ToxSocks is able to connect to a remote network with socks protocol, but in my case it only worked with exactly one socks proxy server. In my special case I had to connect through several „chained“ proxy servers. Example:

localhost  <–>  socksProxy1  <–>  socksProxy2   <—>  remoteNetwork

This was not working with socks stand alone. On Linux you can use „proxychains“ to make a connection chain with several (socks-) proxies.

Install Proxy-Chains:

user@laptop:~$ sudo yum install proxychains

Configure the proxies and the chain:

user@laptop:~$ vim /etc/proxychains.conf

I have defined 2 socks clients in one chain:

# add proxy here ...
# meanwile
# defaults set to "tor"
#socks4 9050
socks5 1080
socks5 1080

With that configuration your connection looks like this:

localhost  <–>  <–>  <–>  remoteNetwork

Now, how to use this? It’s quite simple: proxychains <command> <paramters>
Just place „proxychains“ in front of the command you would like to execute.


Remote Desktop:

proxychains rdesktop -u <Domain>\<user> -p <password> -z -k de -g 1366x768 <ip>

Explanation:  „-z“  activates compression ,  „-k de“ sets the keyboard to german layout,  „-g 1366×768“ sets the Display Size. On a shell you have to escape with \.


Samba-Client / SMB:

proxychains smbclient -U <username>%<password> -W <workgroup> \\<ip>\<share>

Explanation: with this command you can connect via smb protocol to a samba share. You need to take your windows username, password, and the Windows Workgroup. On a shell you have to escape with \.


Install HP Printer (MultiFuncion Device – MFD) DeskJet 3050a on RHEL / Linux

For RedHat Enterprise Linux you need to install HPLIP manually:

There is also the link to download the hplip-3.12.11_rhel-6.0.x86:64.rpm package.

Impotant: The hplip version that is provided by the RedHat Package manager is in version 3.10.9. That version DOES NOT support the DeskJet 3050a!

I used the installation manual from the link above. At Step 3 (Installing rpm package) I got the error :

file /usr/lib64/ from install of hplipfull-3.12.11-0.x86_64 conflicts with file from package hplip-libs-3.10.9-3.el6.x86_64

To solve this, I used the –replaceFiles parameter:

HP Lip

Then run

sudo hp-setup

Then you can find the printer by specifying the IP:

HP Device Manager - Setup

HP Device Manager - Setup