glances – new way to look at contention

glances is like top/htop but little different. It shows you sort based on contention (smartly and automatically) unless you change that and hence if you just want to check what is biggest bottleneck in system, then head over to glances quickly. Here is quick description from dnf info command

 

Name : glances
Version : 2.11.1
Release : 2.fc28
Arch : noarch
Size : 3.2 M
Source : glances-2.11.1-2.fc28.src.rpm
Repo : @System
From repo : fedora
Summary : CLI curses based monitoring tool
URL : https://github.com/nicolargo/glances
License : GPLv3
Description : Glances is a CLI curses based monitoring tool for both GNU/Linux and BSD.
:
: Glances uses the PsUtil library to get information from your system.
:
: It is developed in Python.

Display IP address in console login screen

Here is one liner that will add the current IP address in the console login screen (if you are not running X as is case for servers):

 (ip -o -4 a| awk '$2 !="lo" {print "\nIP Address ::"$4}' |tr '\n' ',';echo)>>/etc/issue

Just execute the above command as root. It will add the required code in “/etc/issue” to display the IP address. BTW, you can also use “\4” or “\6” instead of that command to get the IP but that will not work with some old versions of Linux.

Port php mysql scripts to php 7.0 from 5.x version

Recently I got a script or series of scripts that were written for PHP 5.6x and hence used mysql_connect which as you know by now does not work with PHP 7.0. Since there were number of scripts, I thought it would be waste of time to change them manually and wrote a script to fix them. If you have similar situation then probably this few lines could help you.

Since my scripts did not use all the functions so I did not put the sed commands for all of them but you get the idea 🙂

#!/bin/bash - 
#===============================================================================
#
#          FILE: fix_mysql.sh
# 
#         USAGE: ./fix_mysql.sh 
# 
#   DESCRIPTION: 
# 
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (aka), 
#  ORGANIZATION: 
#       CREATED: 03/23/2018 16:35
# Last modified: Fri Mar 23, 2018  04:36PM
#      REVISION:  ---
#===============================================================================

set -o nounset                              # Treat unset variables as an error


### Run as 
#### find . -type f -name \*php -exec ~/fixmysql.sh {} \;

####

# mysql_affected_rows -> mysqli_affected_rows($link)
# mysql_close -> mysqli_close($link)
# mysql_data_seek -> mysqli_data_seek( $result, $offset)
# mysql_errno -> mysqli_errno( $link)
# mysql_error -> mysqli_error( $link)
# mysql_fetch_array -> mysqli_fetch_array( $result, $type)
# mysql_fetch_assoc -> mysqli_fetch_assoc( $result)
# mysql_fetch_lengths -> mysqli_fetch_lengths( $result )
# mysql_fetch_object -> mysqli_fetch_object( $result, $class, $params)
# mysql_fetch_row -> mysqli_fetch_row( $result)
# mysql_field_seek -> mysqli_field_seek( $result, $number)
# mysql_free_result -> mysqli_free_result(result)
# mysql_get_client_info -> mysqli_get_client_info( $link)
# mysql_get_host_info -> mysqli_get_host_info( $link)
# mysql_get_proto_info -> mysqli_get_proto_info( $link)
# mysql_get_server_info -> mysqli_get_server_info( $link)
# mysql_info -> mysqli_info( $link)
# mysql_insert_id -> mysqli_insert_id( $link)
# mysql_num_rows ->  mysqli_num_rows( $result)
# mysql_ping -> mysqli_ping( $link)
# mysql_query -> mysqli_query( $link, $query)
# mysql_real_escape_string -> mysqli_real_escape_string( $link)
# mysql_select_db - > mysqli_select_db( $link, $database)
# mysql_set_charset -> mysqli_set_charset( $link, $charset)
# mysql_stat -> mysqli_stat( $link)
# mysql_thread_id -> mysqli_thread_id( $link)
######


file=$1
sed -i 's/mysql_connect/mysqli_connect/g' $file
sed -i 's/mysql_query(/mysqli_query($con,/g' $file
sed -i 's/mysql_error/mysqli_error/g' $file
sed -i 's/mysql_select_db(/mysqli_select_db($con,/g' $file
sed -i 's/mysql_affected_rows/mysqli_affected_rows($con,/' $file
sed -i 's/mysql_escape_string(/mysqli_escape_string($con/' $file 
sed -i 's/mysql_real_escape_string(/mysqli_real_escape_string($con/' $file 
sed -i 's/mysql_fetch_array/mysqli_fetch_array/g' $file
sed -i 's/mysql_fetch_assoc/mysqli_fetch_assoc/g' $file
sed -i 's/mysql_fetch_row/mysqli_fetch_row/g' $file
sed -i 's/mysql_select_db/mysqli_select_db/g' $file