Linux shell/bash compare decimal numbers

 

Comparing decimal numbers with bash/shell script is bit tricky operation

I use following script to compare decimal numbers

#!/bin/bash
NUM1=2.0
NUM2=3.0
if (( $(echo "$NUM1 < $NUM2" | bc -l) ));
then
  echo $NUM1 is less than $NUM2
else
  echo $NUM2 is less than $NUM1
fi

I have written compare.sh file. To execute above script use bash instead of shell as shown below:

$ bash compare.sh 

 

Linux clear cached memory

 

By clearing cache we can make some free memory.

Clearing cache will drop clean caches, dentries and inodes from memory.

Following are 3 commands to clear cache:

To clear page cache:

$ sync && echo 1 | sudo tee /proc/sys/vm/drop_caches

To clear dentries and inodes:

$ sync && echo 2 | sudo tee /proc/sys/vm/drop_caches

To clear page cache, dentries and inodes:

$ sync && echo 3 | sudo tee /proc/sys/vm/drop_caches

 

Ubuntu install memcached from source

 

Following are steps to install memcached from source:

  • Download latest version of memcached from http://memcached.org, uncompress it and enter into uncompressed directory.
  • Install dependencies make and libevent-dev with apt-get.
$ apt-get install libevent-dev make
  • After installation is completed run following commands:
$ ./configure

$ make

$ make install

This will complete installation of memcached.

Above installation will install will copy memcached executable file in path “
/usr/local/memcached/bin/memcached

Now create an alias of memcahed executable in /usr/bin with following command:

$ ln -s /usr/local/memcached/bin/memcached /usr/bin/memcached

Start memcached in localhost

$ memcached -u root -d -m 1024 -p 11211 -l localhost

Above command will start memcached with 1GB memory on port 11211.

To check memcached stats use following command:

$ echo "stats" | nc localhost 11211

It will display some stats related to memcached.

iptables allow one ip address

 

To allow one trusted IP address to access all incoming packets add following line in iptables-precursor:

iptables -A INPUT -s 192.168.2.2 -j ACCEPT

where 192.168.2.2 is the IP address I would like to allow, change the IP address as per your requirement.

After adding above line run following commands to get it updated:

$ source iptables-precursor

$ iptables-save > iptables

In above commands I used relative pats for iptables-precursor and iptables.

List and Kill Zombie process

 

On Unix and Unix-like computer operating systems, a zombie process or defunct process is a process that has completed execution but still has an entry in the process table. This entry is still needed to allow the parent process to read its child’s exit status.

To list all Zombie process use following command:

$ ps aux | awk '{ print $8 " " $2 }' | grep -w Z

Unlike normal processes, the kill command has no effect on a zombie process.

To remove all zombie processes from process table we need to reboot the server.

rsyslogd-2039: Could not open output pipe /dev/xconsole

Recently while trying to install centralized logging server with rsyslog I got following error:

rsyslogd-2039: Could not open output pipe ‘/dev/xconsole’

Solution to resolved the issue:

Open /etc/rsyslog.d/50-default.conf and got to last line.

Default last line should appear as follows:

#*.=notice;*.=warn      |/dev/xconsole

Change it as follows:

*.=notice;*.=warn |/dev/console

Difference between 2 lines is, in default line there is a tab space delimiter after warn and in second line there should be a white space delimiter.

Best open source webmail clients

 

There are too many webmail clients are available on web.

Choosing best out of them is quit difficult task for any one.

After exploring tens of webmail clients, I will vote for following webmail client as top 3  webmail clients:

  • Roundcube: I would rate it as the best and easy to install. It has rich text editor and clent side filtering support. Also it hase good web interface.

RoundCube

RoundCube

  • Zimbra: Not explored much about, but based on futures its quite a popular webmail

Zimbra

  • SquirrelMail: Its basic webmail with basic web interface. There is no rich text editor support. There are lot of plugins available for SquirrelMail. 

SquirrelMail

SquirrelMail

All above webmails are open source.

Ubuntu vsftpd 550 permission denied upload

While configuring vsftp I am stuck with the error “550 Permission denied.”

After debugging for quite a bit time and playing with vsftpd.conf editing following 3 configurations are worked for me:

anonymous_enable=NO
local_enable=YES
write_enable=YES

In final final vsftpd.conf file following configurations available:

listen=YES
anonymous_enable=NO
anon_root=/home/user
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/private/vsftpd.pem

After doing any changes in vsftpd.conf file you need restart vsftpd daemon to change make the effect.

In Ubuntu/Debian operating systems use following command to restart vsftpd:

$ service vsftpd restart

Apache httpd redirect all requests to https

 

To redirect all http request to https add following rule in apache2.conf or httpd.conf or .htaccess file.

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://www.example.com/secure

I am added above rule in .htaccess file which is secure directory. This rule will redirect all request coming to /secure directory to https authontication.

After adding restart apache2/httpd and test.

Roundcube SMTP Error (250): Authentication failed

Recently while trying to install roundcube I am stuck with the error “roundcube SMTP Error (250): Authentication failed”.

With the error the clear hint is there should be some issue with SMTP setting, so I checked all SMTP settings and I had bit doubt on following settings.

$rcmail_config['smtp_user'] = '%u';

$rcmail_config['smtp_pass'] = '%p';

After doing some experiments with my main.inc.php file following tweaks are worked for me.

$rcmail_config['smtp_user'] = '';

$rcmail_config['smtp_pass'] = '';

-Sany