How to display load average in terminal titlebar

If you’ve managed a number of Linux servers, then you probably know what it’s like to have several terminal windows running top on your desktop.

There is a better way to do this. You can display load average in real time in your terminal titlebar.

Use this script:

#!/usr/bin/perl -w
use strict;
$|++;
my $host=`/bin/hostname`;
chomp $host;
while(1) {
open(LOAD,"/proc/loadavg") || die "Couldn't open /proc/loadavg: $!\n";
my @load=split(/ /,<LOAD>);
close(LOAD);
print "\033]0;";
print "$host: $load[0] $load[1] $load[2] at ", scalar(localtime);
print "\007";
sleep 2;
}

Save this as a script called tl, and copy it to your ~/bin directory.

When you’d like to have titlebar replaced with the name, load average, and current time of the machine you’re logged into, just run tl&

When your job is finished, just do: killall tl before logging out.
Or, if you want to automate this, you can try:

$echo 'killall tl > /dev/null 2>&1' >> ~/.bash_logout

That’s all.

 

 


If you liked the post, we should get connected - follow me on Twitter

How to “cd” into a directory with name like “-test”

If you’ll ever have a situation that you need to enter into a directory with a name like “-test” or any other starting with “-“, this is a post for you.

Solution: You need to use — argument.

So, one way to do this is:

cd -- -test

Other way to do this is to specify the path explicitly:

cd ./-test

Btw, if you would like to delete a directory called like this, you should do next:

rm -r -- -test

If you liked the post, we should get connected - follow me on Twitter

Get MySQL Database Size from Terminal

If you need to find out the size of MySQL databases you use from terminal, the following query will list all the databases with their respective sizes:

mysql> SELECT table_schema "database", sum(data_length + index_length)/1024/1024 "size in MB" FROM information_schema.TABLES GROUP BY table_schema;

The result you’ll get will be something like:

| database           | size in MB     |
+--------------------+----------------+
| test1              | 13542.68241349 | 
| test2              |  1522.23837675 | 
| test3              | 26532.27326164 | 
| information_schema |     0.00390626 | 
+--------------------+----------------+
4 rows in set (0.02 sec)

If you have large databases, you can show the result in gigabytes with this query:

mysql> SELECT table_schema "database", sum(data_length + index_length)/1024/1024/1024 "size in GB" FROM information_schema.TABLES GROUP BY table_schema;

If you liked the post, we should get connected - follow me on Twitter

Mass manipulation and the 5 monkeys experiment

Social control and technology to manipulate the masses, both at local and global level is a serious topic. There are numerous manipulation methods applied for decades. The fact is that with each following generation of people, those methods achieve better results. If you don’t know a lot about this topic, for beginning you can read this.

Then, take a look at one experiment:

 

Quite interesting. And now just think – did you ever wonder why you ( and people around you ) follow some matrix even you think that it’s stupid or you know a better way, did you ever follow some rules no matter they make no sense to you, … ? Who created those matrix, those rules, etc?

Are we just a group monkeys?

 


If you liked the post, we should get connected - follow me on Twitter

How to run scripts in Linux faster than Cron does

Cron is an amazing job scheduler. But, when it comes to running your scripts in less than every minute, it can’t help.

With Cron, you can run your scripts every minute, but not in shorter period of time.

This problem can be solved with simple bash script. For example, if you need to run a PHP script on every 20 seconds, you can create a bash script like this:

#!/bin/bash
#Name:myscript.sh
#Desc:Run script in every 20 seconds
while (sleep 20 && php /path_to_your_script/your_script_name.php) &
do
 wait $!
done

Then, make script executable, and add it to the system startup. That’s all.

 

 


If you liked the post, we should get connected - follow me on Twitter