2015 in review

The WordPress.com stats helper monkeys prepared a 2015 annual report for this blog.

Here’s an excerpt:

The concert hall at the Sydney Opera House holds 2,700 people. This blog was viewed about 21,000 times in 2015. If it were a concert at Sydney Opera House, it would take about 8 sold-out performances for that many people to see it.

Click here to see the complete report.

How to use Proxy server to access Internet at command line Interface

You can use http_proxy to connect to Internet when you are using utilities like wget, lynx, elinks, curl etc. You need a proxy server & port and in some cases a username & password for enabling access via proxy server.

$ export http_proxy=http://server-ip:port/

$ export http_proxy=http://USERNAME:PASSWORD@proxy-server.domain.com:port/

Please note that the above scenario is only applicable to servers not connected directly to Internet. After running the above commands, you can use wget, curl etc normally without any issues.

 

Bash script to monitor disk space in a linux server and sent alert mails

The following script can be used to monitor disk space of any particular partition which is critical and send alert emails if it exceeds any set limit which can be rectified upon receipt of the email.

#!/bin/bash
CURRENT=$(df / | grep / | awk ‘{ print $5}’ | sed ‘s/%//g’)
THRESHOLD=90

if [ “$CURRENT” -gt “$THRESHOLD” ] ; then
mail -s ‘Disk Space Alert’ -S smtp=IP:Port  test@domain.com << EOF
Your / partition remaining free space is critically low. Used: $CURRENT%
EOF
fi

To keep it in monitoring mode, you can set a cron job to run the script every 5 minutes so that it will check it periodically.

PS: The SMTP server IP & Port pair can be used if the local server is not set to sent emails. Here, I have used a remote SMTP server. In case of sendmail, you need to add the IP of the localserver to relay in remote smtp server in the file /etc/mail/access.

Ref: https://www.freebsd.org/doc/handbook/sendmail.html

Yum error : libxml2.so.2: cannot open shared object file: No such file or directory

Sometimes, you may come across the following errors while trying to install packages in a server using yum.

# yum install lsscsi
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

libxml2.so.2: cannot open shared object file: No such file or directory

Please install a package which provides this module, or
verify that the module is installed correctly.

It’s possible that the above module doesn’t match the
current version of Python, which is:
2.4.3 (#1, Jan 9 2013, 06:47:03)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)]

If you cannot solve this problem yourself, please go to
the yum faq at:
http://wiki.linux.duke.edu/YumFaq
In such cases, you may need to install the package libxml2 to fix the error.

Since the package installer yum relies on libxml2, it cannot be used to reinstall libxml2. You can copy the file from a different machine running the same version of CentOS and arch. The issue will be fixed.

 

 

-bash: /usr/bin/id: Too many open files in system

Today I faced an issue while logging into a VPS from node.

 

# vzctl enter 101
entered into CT 101
-bash: /bin/egrep: Too many open files in system
-bash: /bin/egrep: Too many open files in system
-bash: /bin/egrep: Too many open files in system

While checking the UBC parameters for the respective VPS server, by viewing the output of /proc/user_beancounters, I could see that the parameter ‘numfile’ was hitting failcount. Numfile is the parameter for number of open files in a VPS. Increasing the limit fixed the issue.

# vzctl set 101 –numfile 500000:500000 –save
UB limits were set successfully
Saved parameters for CT 101

 

How to reset WordPress admin password via command line in cPanel

We can reset WordPress Database admin passwords via command line in cPanel server for domains. First, we need to find which Database is used by the domain for WordPress. You can find it via checking the Database name given in the file ‘wp-config.php’.

Upon finding that, login to MySQL prompt.

# mysql

mysql> use databasename;

where databasename is the database in which WordPress is installed.

mysql> SELECT ID,user_login,user_pass FROM wp_users;

+—-+————+————————————+
| ID | user_login | user_pass |
+—-+————+————————————+
| 1 | admin | $P$B05GJOhuMCFlxtYsYjA8P/sX0svNw81 |

mysql> UPDATE wp_users SET user_pass =”da6809dcb5a5e4ab9ab8c81adc995c7e”;

mysql> SELECT ID=1,user_login,user_pass FROM wp_users;
+——+————+———————————-+
| ID=1 | user_login | user_pass |
+——+————+———————————-+
| 1 | admin | da6809dcb5a5e4ab9ab8c81adc995c7e |

You can generate a MD5 encrypted password using any of the online tools available.

 

tcptrack command

tcptrack command displays the status of TCP connections that it sees on a given network interface. tcptrack monitors their state and displays information such as state, source/destination addresses and bandwidth usage in a sorted, updated list very much like the top command.

Install tcptrack

# cd /usr/src
# wget http://dag.wieers.com/rpm/packages/tcptrack/tcptrack-1.1.5-1.2.el5.rf.x86_64.rpm
# rpm -ivh tcptrack-1.1.5-1.2.el5.rf.x86_64.rpm

Sometimes, you may find dependency errors while trying to install tcptrack command.

# rpm -ivh tcptrack-1.1.5-1.2.el5.rf.x86_64.rpm
warning: tcptrack-1.1.5-1.2.el5.rf.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
error: Failed dependencies:
libpcap.so.0.9.4()(64bit) is needed by tcptrack-1.1.5-1.2.el5.rf.x86_64

In such cases, install the dependency package. In this case, do the following:

# yum install libpcap

tcptrack requires only one parameter to run i.e. the name of an interface such as eth0, eth1 etc. Use the -i flag followed by an interface name that you want tcptrack to monitor.
# tcptrack -i eth0
# tcptrack -i eth1

You can also monitor a particular port using tcptrack.

# tcptrack -i eth0 port 25

# tcptrack -i eth1 port 80