Tag Archives: linux

18 Dec

MySQL Memory Usage Limits on 32 bit Linux

I’m having RHEL 5 (32-bit) and MySQL-5.

I was trying to check how much is the Memory Utilization limits for MySQL 5 on 32bit OS.

We can easily calculate the maximum capacity of the address space is 2^32 bytes and that is where these limits come from.
* For MYSQL 5.0: Following are memory (storage) limits:

Max DB size:  Unlimited
Max table size:  MyISAM: 256TB; Innodb: 64TB
Max row size: 64 KB
Max columns per row: 4096
Max Blob/Clob size: 4 GB (longtext, longblob)
Max CHAR size: 64 KB (text)
Max NUMBER size: 64 bits
Min DATE value: 1000
Max DATE value: 9999
Max column name size: 64

* OS Memory Limitations:

Maximum x86 per-process virtual address space for Red-Hat Linux Version
Version 4: ~ 4GB
Version 5: ~ 3GB
* Server Parameters memory allocation limits:

For following buffers:
• key_buffer_size
• join_buffer_size
• myisam_sort_buffer_size
• sort_buffer_size
– Maximum allowable setting is 4GB.
– As of MySQL 5.1.23, values larger than 4GB are allowed for 64-bit platforms.

Others:
net_buffer_length -1MB.
read_buffer_size – 2GB.
read_rnd_buffer_size – 2GB.

* About globally limiting memory usage by MySQL Server:

MySQL is not having any other parameter that directly limits the memory usage. It’s these global buffers / server variables are the only setting which extends / shrinks server memory usage limits.

Eg. max_connections, variable for specifying number of simultaneous connection, depends on OS limits to handle file handlers. No documented limit is there for the same.

References:
http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html
http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html
http://en.wikipedia.org/wiki/Comparison_of_relational_database_management_systems
http://www.redhat.com/rhel/compare/
http://support.bull.com/ols/product/system/linux/redhat/help/kbf/g/inst/PrKB11417

04 Dec

How to echo colored text in linux shell script

Having a colourful display on shell script is something that’d beautify your experience. Using colour text and echos will help you to highlight and distinguish the shell output on a linux prompt.

Here’s how you can have colored text in linux shell, try following command on your bash:

bash $] tput setaf 1
You will see your text color will turn red.
To reset it you can type following command to make text color white
bash $] tput setaf 7

or to reset everything again text modes
bash $] tput sgr0

Same things you can use in your bash script to colorize output.

Create following sample bash script for colourize echo:

#try.sh
txtrst=$(tput sgr0) # Text reset
txtred=$(tput setaf 1) # Red
echo “Welcome to ${txtred} kedar.nitty-witty.com ${txtrst}!”

The coloured text output is as follows::

colored-shell-script

If you need more colors, you may define them as follows in shell script:

Other variables you can define as follows:
txtgrn=$(tput setaf 2) # Green
txtylw=$(tput setaf 3) # Yellow
txtblu=$(tput setaf 4) # Blue
txtpur=$(tput setaf 5) # Purple
txtcyn=$(tput setaf 6) # Cyan
txtwht=$(tput setaf 7) # White
txtrst=$(tput sgr0) # Text reset.

Following are the tput details further:
tput setab [1-7] : Set a background colour using ANSI escape
tput setb [1-7] : Set a background colour
tput setaf [1-7] : Set a foreground colour using ANSI escape
tput setf [1-7] : Set a foreground colour

tput Text Mode Capabilities:

tput bold : Set bold mode
tput dim : turn on half-bright mode
tput smul : begin underline mode
tput rmul : exit underline mode
tput rev : Turn on reverse mode
tput smso : Enter standout mode (bold on rxvt)
tput rmso : Exit standout mode
tput sgr0 : Turn off all attributes (doesn’t work quite as expected)

I hope you liked this. Happy & colourful shell scripting.  🙂

11 Jan

Simple Shell Script to Monitoring Disk Space on a Linux Machine

This article explain a way to get a mail as soon as the disk usage reaches to its critical level to avoid issues later. To set a simple monitor on Linux / Unix, I have two simple scripts:

  • DSAlert.sh : Shell script for retrieving disk space percentages and put in to a cron job.
  • DiskSpace_Alert.pl : Perl script for sending an email.

Following is the disk monitor shell script which will execute the perl file for sending alert email.

#DSAlert.sh
#!/bin/sh
#Retrive disk space info
df=`df -Pl  | grep "^/dev" | awk '{print $5, $6}' | sed "s/%//"`

#Reference: df
echo “$df” | while read percent fs
do
#If Disk Usage increases above 90% send an email.
if [ $percent -ge 90 ] ; then
#Calling a perl file with parameters for sending an email.
`/opt/lampp/bin/perl DiskSpace_Alert.pl $fs is $percent percent full`
fi
done

Perl Script for sending an email:

# DiskSpace_Alert.pl
#!perl
use MIME::Lite;

#Reference : Mime-Lite

# set up email
$to = “my-mail-id\@domain.com”;
$from = “Diskmonitor\@ServerName.com”;
$subject = “Disk_Alert”;
$message = “Disk Space issue.\nActions Required:\n”.”@ARGV”;
# send email
email($to, $from, $subject, $message, $file);

# email function
sub email
{
# get incoming parameters
local ($to, $from, $subject, $message, $file) = @_;
# create a new message
$msg = MIME::Lite->new(
From => $from,
To => $to,
Subject => $subject,
Data => $message);
# send the email

MIME::Lite->send(‘smtp’, ‘localhost’, Timeout => 60);
$msg->send();
}
Setting up a crontab for monitoring:

Crontab –e
* * * * * sh  full/path/to/DSAlert.sh

And we’re done with the Linux/Unix Disk Monitoring alerts.

Instructions for setting up timing for crontab:

+----------------> minute (0 - 59)
|  +-------------> hour (0 - 23)
|  |  +----------> day of month (1 - 31)
|  |  |  +-------> month (1 - 12)
|  |  |  |  +----> day of week (0 - 6) (Sunday=0 or 7)
|  |  |  |  |
*  *  *  *  *

10 Jan

Linux Shell Commands – quick how-tos

Following are linux commands, tricks for doing regular tasks.

Rename files: replace space by _ in linux:

for files in *; do mv "$files" `echo $files | tr ' ' '_'`; done

Change case of multiple file names:

for files in *; do mv $files `echo $files | tr '[:upper:]' '[:lower:]'`; done

Find files having large size:

ls -hlRtr | awk '{print $5 " " $6 "-" $7 " "$9}' | grep '[0-9]G ' 

– Variants: grep ‘[0-9][0-9][0-9]M’ will give you files having sizes xxxMBs.

Find and replace text from multiple files :

find ./ -type f | xargs perl -pi -w -e 's/SEARCH-TERM/REPLACE-TERM/g;'

Find text in file:

find . -name "*.php" | xargs grep " order by l.ID "
find . -name "*.pl" | xargs grep "virtualTourUrl"
grep *.* "Pattern"

Find and Delete file within last one hour:

find /some/dir -type f -mmin +60 | xargs rm -f
find . -cmin +60 -exec rm -f {} \;

Find files last modified / accessed – copy to other directory:

find . -mtime +1 -exec cp {} TARGET_FOLDER \;

– atime..last access
– mtime..last modify
– ctime..last status change

Replace content of a file:

perl -pi -e "s/kedar/radek/g" a.txt
perl -pi -e "s/OLDTEXT=OLDVALUE/NewText=NewValue/g" *.*

Find a.txt and Replace content by string comparison and save in to other file:

find ./ -name "a.txt" -exec sed 's/radek/kedar/g' {} \; > b.txt

Find files modified in last n days:

find *.sql -mtime +n -exec ls -l --sort=time {} \;

Create and Extract a Tar file:

tar -cvf /path/to/file.tar /path/to/source/ archived
tar -xvf /path/to/file.tar

A quick sftp – secure file transfer program to transfer files between linux/unix machines:

sftp usename@hostname/ipaddress
password: ****
sftp> ls #executed on remote machine
sftp> lls #executed on local machine
sftp> get *.* #download all files from remote machine to local machine
sftp> put *.* #upload files to remote machine

- Create directory in sftp: mkdir [For local: lmkdir]
- Change directory in sftp: cd [For local: lcd]
- get / mget : download files to local linux machine
- put / mput : upload files to remote linux machie
-- Kedar Vaijanapurkar --