Tuesday 25 September 2012

Linux Real Time Issues-5

File system check failed. Won't boot.


Here, try this one.

Bootup from Live CD, than go to terminal and:

sudo blkid

it will return something like:

/dev/sda5: UUID="eae4ddca-b9b1-48d4-abba-e26bc44027a4" TYPE="ext4"
/dev/sda6: UUID="7ff08df9-693a-4841-a459-b934c672a821" TYPE="swap"

(This is mine result, sda5 is my ubuntu partition).

Ok

copy its UUID

Than open on your filesystem file /etc/fstab

Search for your sda and paste UUID there. (replace wrong UUID number)


---------------------------------------------------------------------------------------
root file system check failed

Been having a few issues. Basically I'm locked of my laptop.

It says: Root filesystem check failed
A maintenance shell will now be started
CONTROL-D will terminate this shell and reboot the system
root@charley-laptop:~# 



It looks like you need to run fsck on your root partition. You can do this from a live CD (make sure the partition is not mounted) or you can do it from the maintenance shell if you remount the root partition read only.

In either case just make sure the root partition is not mounted read/write.

Code:
fsck /dev/sdX
where X is the partition for /. You can do a trail run with the -N switch.



It 'n' to not ignore the error.

Run fsck again but try using a backup superblock instead of the main one. That one may be corrupted.

Run the trail run with the -N switch to see what it says.


---------------------------------------------------------------------------------------------
So you using GDM. It sounds like it may be corrupted. What happens if you drop to a virtual terminal (ctrl + alt + f1) and restart GDM ?

Code:
sudo service gdm restart
or
Code:
sudo /etc/init.d/gdm restart

------------------------------------------------------------------------------------------------------
When I boot at this moment I get the following message during the boot,
when the file system of sda4 (the new installation) is being checked.

================================================== =========================

* Checking file systems...
1176

fsck 1.40.8 (13-mar-2008)
fsck.ext3: Unable to resolve 'UUID=88202516-902e-4382-9291-680daed83138'
fsck died with exit status 8
[fail]
* File system check failed.
A log is being saved in /var/log/fsck/checkfs
if that location is writable.
please repair the file system manually.

* A maintenance shell will now be started.

CONTROL-D will terminate this shell and resume system boot.

bash: no job control in this shell
bash: groups: command not found
bash: lesspipe: command not found
bash: command: command not found
bash: the: command not found
bash: dircolors: command not found
bash: command: command not found
bash: the: command not found
root@ultraros-desktop:~#

================================================== ========================

When I press "CONTROL-D" or "Exit" or "Reboot" the system boots up

and I can use her, but I prefer to solve this so I can boot the normal way.

he log file (/var/log/fsck/checkfs) contains

================================================== ===========================

Log of fsck -C3 -R -A -a
Mon Sep 8 15:18:30 2008

fsck 1.40.8 (13-Mar-200
fsck.ext3: Unable to resolve 'UUID=88202516-902e-4382-9291-680daed83138'

fsck died with exit status 8

Mon Sep 8 15:18:30 2008
----------------
Code:
cat /etc/fstab
Code:
joop@UltraRos-desktop:~$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
# /dev/hda4
UUID=620f6373-ceb4-43d2-a5d8-1f58338de857 /               ext3    defaults,errors=remount-ro 0       1
# /dev/hda3
UUID=88202516-902e-4382-9291-680daed83138 /media/hda3     ext3    defaults        0       2
# /dev/hda5
UUID=76D0374CD037123B /media/hda5     ntfs    defaults,umask=007,gid=46 0       1
# /dev/hda6
UUID=13DFA768E0039D61 /media/hda6     ntfs    defaults,umask=007,gid=46 0       1
# /dev/hda1
UUID=22de6324-6467-428b-9d2f-4074c5f39b8c none            swap    sw              0       0
# /dev/hda7
UUID=ed74fe7a-4758-4fbf-a753-0b2416d064c4 none            swap    sw              0       0
/dev/hdc        /media/cdrom0   udf,iso9660 user,noauto,exec 0       0
/dev/hdd        /media/cdrom1   udf,iso9660 user,noauto,exec 0       0
/dev/fd0        /media/floppy0  auto    rw,user,noauto,exec 0       0
joop@UltraRos-desktop:~$
================================================== ===========================

I hope this will help to find a solution.

ok, this line "# /dev/hda3
UUID=88202516-902e-4382-9291-680daed83138 /media/hda3 ext3 defaults 0 2" has the possibly bad uuid entry, please post the output of this command

Code:
sudo vol_id --uuid /dev/hda3

Monday 24 September 2012

MySql Bascis

Resetting a forgotten MySQL root password


root@steve:~# /etc/init.d/mysqd stop

root@steve:~# /usr/bin/mysqld_safe --skip-grant-tables &
[1] 6702
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6763]: started

root@steve:~$ mysql --user=root mysql
Enter password:



mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root';
Query OK, 2 rows affected (0.04 sec)
Rows matched: 2  Changed: 2  Warnings: 0


mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

mysql> exit
Bye


root@steve:~# /etc/init.d/mysql start
Starting MySQL database server: mysqld.
Checking for corrupt, not cleanly closed and upgrade needing tables..




$ mysqladmin -u root password NEWPASSWORD


$ mysqladmin -u root -p'oldpassword' password newpass


$ mysqladmin -u root -p'abc' password '123456'

$ mysqladmin -u vivek -p oldpassword password newpass


MySql Commands:

Logging In

$ mysql -u <username> -p
Enter password:

Create database

mysql> CREATE DATABASE <database>; 

mysql> CREATE DATABASE vworks; 

We can now check for the presence of this database by typing:
mysql> SHOW DATABASES;
+-----------+
| Database  |
+-----------+
| mysql     |
| vworks    |
+-----------+
2 rows in set (0.06 sec)
Deleting or DROPing a database
DROP DATABASE <database>

Granting Privileges on the new database

GRANT <privileges> 
ON <database> 
TO <user> 
[IDENTIFIED BY <password>] 
[WITH GRANT OPTION]
mysql> GRANT ALL PRIVILEGES 
    -> ON vworks.* 
    -> TO newuser@localhost 
    -> IDENTIFIED BY 'newpassword';  

Revoking privileges




mysql> REVOKE ALL PRIVILEGES 
    -> ON vworks.* 
    -> FROM badvworks@localhost;  

mysqlhotcopy


 mysqlhotcopy -u <username> -p <database> /backup/location/


mysqldump

 mysqldump -u <username> -p <database> [<table>] > file.sql


 mysqldump -u admin -p vworks > vworks.sql


Restoring a Dump

$ mysql -u admin -p vworks < vworks.sql

$ mysql -u admin -p vworks < artist.sql

$ mysql -u admin -p < vworksDB.sql


Optimising a dump

$ mysqldump -u admin -p --opt vworks > vworks.sql

$ mysqldump -u admin -p --databases vworks | \
> mysql -u backup -p MyPassword -h remote.server.com 



mysql> CREATE DATABASE vworks2; 


Remote Client Connection


$ mysql -u <username> -p -h <host>


For example to connect to a fictional vworks.keithjbrown.co.uk server:
$ mysql -u admin -p -h vworks.keithjbrown.co.uk

Non-Interactive Commands


$ mysql -u admin -p vworks -e 'SELECT cds.artist, cds.title FROM cds'

Enter password: 
+------------+------------------------------+
| artist     | title                        |
+------------+------------------------------+
| Jamiroquai | A Funk Odyssey               |
| Various    | Now 49                       |
| westlife   | westlife                     |
| Various    | Eurovision Song contest 2001 |
| Abba       | Abbas Greatest Hits          |




1. How to change the MySQL root user password?

# mysqladmin -u root -ptmppassword password 'newpassword'

# mysql -u root -pnewpassword

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

2. How to check whether MySQL Server is up and running?

# mysqladmin -u root -p ping
Enter password:
mysqld is alive

3. How do I find out what version of MySQL I am running?

Apart from giving the ‘Server version’, this command also displays the current status of the mysql server.


# mysqladmin -u root -ptmppassword version

mysqladmin  Ver 8.42 Distrib 5.1.25-rc, for redhat-linux-gnu on i686
Copyright (C) 2000-2006 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version          5.1.25-rc-community
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/lib/mysql/mysql.sock
Uptime:                 107 days 6 hours 11 min 44 sec

Threads: 1  Questions: 231976  Slow queries: 0  Opens: 17067
Flush tables: 1  Open tables: 64  Queries per second avg: 0.25

4. What is the current status of MySQL server?

# mysqladmin -u root -ptmppassword status

Uptime: 9267148
Threads: 1  Questions: 231977  Slow queries: 0  Opens: 17067
Flush tables: 1  Open tables: 64  Queries per second avg: 0.25
The status command displays the following information:
  • Uptime: Uptime of the mysql server in seconds
  • Threads: Total number of clients connected to the server.
  • Questions: Total number of queries the server has executed since the startup.
  • Slow queries: Total number of queries whose execution time waas more than long_query_time variable’s value.
  • Opens: Total number of tables opened by the server.
  • Flush tables: How many times the tables were flushed.
  • Open tables: Total number of open tables in the database.

5. How to view all the MySQL Server status variable and it’s current value?

# mysqladmin -u root -ptmppassword extended-status
+-----------------------------------+-----------+
| Variable_name                     | Value     |
+-----------------------------------+-----------+
| Aborted_clients                   | 579       |
| Aborted_connects                  | 8         |
| Binlog_cache_disk_use             | 0         |
| Binlog_cache_use                  | 0         |
| Bytes_received                    | 41387238  |
| Bytes_sent                        | 308401407 |
| Com_admin_commands                | 3524      |
| Com_assign_to_keycache            | 0         |
| Com_alter_db                      | 0         |
| Com_alter_db_upgrade              | 0         |

6. How to display all MySQL server system variables and the values?

# mysqladmin  -u root -ptmppassword variables
+---------------------------------+---------------------------------+
| Variable_name                   | Value                           |
+---------------------------------+---------------------------------+
| auto_increment_increment        | 1                               |
| basedir                         | /                               |
| big_tables                      | OFF                             |
| binlog_format                   | MIXED                           |
| bulk_insert_buffer_size         | 8388608                         |
| character_set_client            | latin1                          |
| character_set_database          | latin1                          |
| character_set_filesystem        | binary                          |

skip.....

| time_format                     | %H:%i:%s                        |
| time_zone                       | SYSTEM                          |
| timed_mutexes                   | OFF                             |
| tmpdir                          | /tmp                            |
| tx_isolation                    | REPEATABLE-READ                 |
| unique_checks                   | ON                              |
| updatable_views_with_limit      | YES                             |
| version                         | 5.1.25-rc-community             |
| version_comment                 | MySQL Community Server (GPL)    |
| version_compile_machine         | i686                            |
| version_compile_os              | redhat-linux-gnu                |
| wait_timeout                    | 28800                           |
+---------------------------------+---------------------------------+

7. How to display all the running process/queries in the mysql database?

# mysqladmin -u root -ptmppassword processlist
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 20 | root | localhost |    | Sleep   | 36   |       |                  |
| 23 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
You can use this command effectively to debug any performance issue and identify the query that is causing problems, by running the command automatically every 1 second as shown below.
# mysqladmin -u root -ptmppassword -i 1 processlist
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 20 | root | localhost |    | Sleep   | 36   |       |                  |
| 23 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+

+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 24 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+

8. How to create a MySQL Database?

# mysqladmin -u root -ptmppassword create testdb

# mysql -u root -ptmppassword

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 705
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| sugarcrm           |
| testdb             |
+--------------------+
4 rows in set (0.00 sec)


Note: To display all tables in a database, total number of columns, row, column types, indexes etc., use the mysqlshow command that we discussed in our previous articles.

9. How to Delete/Drop an existing MySQL database?

# mysqladmin -u root -ptmppassword drop testdb

Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.

Do you really want to drop the 'testdb' database [y/N] y
Database "testdb" dropped

# mysql -u root -ptmppassword

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 707
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| sugarcrm           |
+--------------------+
3 rows in set (0.00 sec)

1. How to change the MySQL root user password?

# mysqladmin -u root -ptmppassword password 'newpassword'

# mysql -u root -pnewpassword
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

2. How to check whether MySQL Server is up and running?

# mysqladmin -u root -p ping
Enter password:
mysqld is alive

3. How do I find out what version of MySQL I am running?

Apart from giving the ‘Server version’, this command also displays the current status of the mysql server.


# mysqladmin -u root -ptmppassword version

mysqladmin  Ver 8.42 Distrib 5.1.25-rc, for redhat-linux-gnu on i686
Copyright (C) 2000-2006 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version          5.1.25-rc-community
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/lib/mysql/mysql.sock
Uptime:                 107 days 6 hours 11 min 44 sec

Threads: 1  Questions: 231976  Slow queries: 0  Opens: 17067
Flush tables: 1  Open tables: 64  Queries per second avg: 0.25

4. What is the current status of MySQL server?

# mysqladmin -u root -ptmppassword status
Uptime: 9267148
Threads: 1  Questions: 231977  Slow queries: 0  Opens: 17067
Flush tables: 1  Open tables: 64  Queries per second avg: 0.25
The status command displays the following information:
  • Uptime: Uptime of the mysql server in seconds
  • Threads: Total number of clients connected to the server.
  • Questions: Total number of queries the server has executed since the startup.
  • Slow queries: Total number of queries whose execution time waas more than long_query_time variable’s value.
  • Opens: Total number of tables opened by the server.
  • Flush tables: How many times the tables were flushed.
  • Open tables: Total number of open tables in the database.

5. How to view all the MySQL Server status variable and it’s current value?

# mysqladmin -u root -ptmppassword extended-status
+-----------------------------------+-----------+
| Variable_name                     | Value     |
+-----------------------------------+-----------+
| Aborted_clients                   | 579       |
| Aborted_connects                  | 8         |
| Binlog_cache_disk_use             | 0         |
| Binlog_cache_use                  | 0         |
| Bytes_received                    | 41387238  |
| Bytes_sent                        | 308401407 |
| Com_admin_commands                | 3524      |
| Com_assign_to_keycache            | 0         |
| Com_alter_db                      | 0         |
| Com_alter_db_upgrade              | 0         |

6. How to display all MySQL server system variables and the values?

# mysqladmin  -u root -ptmppassword variables
+---------------------------------+---------------------------------+
| Variable_name                   | Value                           |
+---------------------------------+---------------------------------+
| auto_increment_increment        | 1                               |
| basedir                         | /                               |
| big_tables                      | OFF                             |
| binlog_format                   | MIXED                           |
| bulk_insert_buffer_size         | 8388608                         |
| character_set_client            | latin1                          |
| character_set_database          | latin1                          |
| character_set_filesystem        | binary                          |

skip.....

| time_format                     | %H:%i:%s                        |
| time_zone                       | SYSTEM                          |
| timed_mutexes                   | OFF                             |
| tmpdir                          | /tmp                            |
| tx_isolation                    | REPEATABLE-READ                 |
| unique_checks                   | ON                              |
| updatable_views_with_limit      | YES                             |
| version                         | 5.1.25-rc-community             |
| version_comment                 | MySQL Community Server (GPL)    |
| version_compile_machine         | i686                            |
| version_compile_os              | redhat-linux-gnu                |
| wait_timeout                    | 28800                           |
+---------------------------------+---------------------------------+

7. How to display all the running process/queries in the mysql database?

# mysqladmin -u root -ptmppassword processlist
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 20 | root | localhost |    | Sleep   | 36   |       |                  |
| 23 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
You can use this command effectively to debug any performance issue and identify the query that is causing problems, by running the command automatically every 1 second as shown below.
# mysqladmin -u root -ptmppassword -i 1 processlist
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 20 | root | localhost |    | Sleep   | 36   |       |                  |
| 23 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+

+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 24 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+

8. How to create a MySQL Database?

# mysqladmin -u root -ptmppassword create testdb

# mysql -u root -ptmppassword
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 705
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| sugarcrm           |
| testdb             |
+--------------------+
4 rows in set (0.00 sec)


Note: To display all tables in a database, total number of columns, row, column types, indexes etc., use the mysqlshow command that we discussed in our previous articles.

9. How to Delete/Drop an existing MySQL database?

# mysqladmin -u root -ptmppassword drop testdb
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.

Do you really want to drop the 'testdb' database [y/N] y
Database "testdb" dropped

# mysql -u root -ptmppassword
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 707
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| sugarcrm           |
+--------------------+
3 rows in set (0.00 sec)

1. How to change the MySQL root user password?

# mysqladmin -u root -ptmppassword password 'newpassword'

# mysql -u root -pnewpassword
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

2. How to check whether MySQL Server is up and running?

# mysqladmin -u root -p ping
Enter password:
mysqld is alive

3. How do I find out what version of MySQL I am running?

Apart from giving the ‘Server version’, this command also displays the current status of the mysql server.
# mysqladmin -u root -ptmppassword version
mysqladmin  Ver 8.42 Distrib 5.1.25-rc, for redhat-linux-gnu on i686
Copyright (C) 2000-2006 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version          5.1.25-rc-community
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/lib/mysql/mysql.sock
Uptime:                 107 days 6 hours 11 min 44 sec

Threads: 1  Questions: 231976  Slow queries: 0  Opens: 17067
Flush tables: 1  Open tables: 64  Queries per second avg: 0.25

4. What is the current status of MySQL server?

# mysqladmin -u root -ptmppassword status
Uptime: 9267148
Threads: 1  Questions: 231977  Slow queries: 0  Opens: 17067
Flush tables: 1  Open tables: 64  Queries per second avg: 0.25
The status command displays the following information:
  • Uptime: Uptime of the mysql server in seconds
  • Threads: Total number of clients connected to the server.
  • Questions: Total number of queries the server has executed since the startup.
  • Slow queries: Total number of queries whose execution time waas more than long_query_time variable’s value.
  • Opens: Total number of tables opened by the server.
  • Flush tables: How many times the tables were flushed.
  • Open tables: Total number of open tables in the database.

5. How to view all the MySQL Server status variable and it’s current value?

# mysqladmin -u root -ptmppassword extended-status
+-----------------------------------+-----------+
| Variable_name                     | Value     |
+-----------------------------------+-----------+
| Aborted_clients                   | 579       |
| Aborted_connects                  | 8         |
| Binlog_cache_disk_use             | 0         |
| Binlog_cache_use                  | 0         |
| Bytes_received                    | 41387238  |
| Bytes_sent                        | 308401407 |
| Com_admin_commands                | 3524      |
| Com_assign_to_keycache            | 0         |
| Com_alter_db                      | 0         |
| Com_alter_db_upgrade              | 0         |

6. How to display all MySQL server system variables and the values?

# mysqladmin  -u root -ptmppassword variables
+---------------------------------+---------------------------------+
| Variable_name                   | Value                           |
+---------------------------------+---------------------------------+
| auto_increment_increment        | 1                               |
| basedir                         | /                               |
| big_tables                      | OFF                             |
| binlog_format                   | MIXED                           |
| bulk_insert_buffer_size         | 8388608                         |
| character_set_client            | latin1                          |
| character_set_database          | latin1                          |
| character_set_filesystem        | binary                          |

skip.....

| time_format                     | %H:%i:%s                        |
| time_zone                       | SYSTEM                          |
| timed_mutexes                   | OFF                             |
| tmpdir                          | /tmp                            |
| tx_isolation                    | REPEATABLE-READ                 |
| unique_checks                   | ON                              |
| updatable_views_with_limit      | YES                             |
| version                         | 5.1.25-rc-community             |
| version_comment                 | MySQL Community Server (GPL)    |
| version_compile_machine         | i686                            |
| version_compile_os              | redhat-linux-gnu                |
| wait_timeout                    | 28800                           |
+---------------------------------+---------------------------------+

7. How to display all the running process/queries in the mysql database?

# mysqladmin -u root -ptmppassword processlist
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 20 | root | localhost |    | Sleep   | 36   |       |                  |
| 23 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
You can use this command effectively to debug any performance issue and identify the query that is causing problems, by running the command automatically every 1 second as shown below.
# mysqladmin -u root -ptmppassword -i 1 processlist
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 20 | root | localhost |    | Sleep   | 36   |       |                  |
| 23 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+

+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 24 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+

8. How to create a MySQL Database?

# mysqladmin -u root -ptmppassword create testdb

# mysql -u root -ptmppassword
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 705
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| sugarcrm           |
| testdb             |
+--------------------+
4 rows in set (0.00 sec)


Note: To display all tables in a database, total number of columns, row, column types, indexes etc., use the mysqlshow command that we discussed in our previous articles.

9. How to Delete/Drop an existing MySQL database?

# mysqladmin -u root -ptmppassword drop testdb
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.

Do you really want to drop the 'testdb' database [y/N] y
Database "testdb" dropped

# mysql -u root -ptmppassword
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 707
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| sugarcrm           |
+--------------------+
3 rows in set (0.00 sec)

Friday 21 September 2012


How To Add New Disk To The Hardware Raid Controller Without Rebooting The Server In Linux:


First find out your RAID hardware as we will need appropriate OS utility to manage the same
from the same vendor. In our case it was lsi which can be managed via Megacli utility.

[root@server 8.02.21_Linux_MegaCLI]# lspci | grep -i raid
07:00.0 RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS 2108 [Liberator] (rev 05)
Lets first install the utilty :
To do this we need to install the Megacli utility on our server Centos6.2.

Step:1. Install the below two packages.
(downlaod from http://www.lsi.com/downloads/Public/MegaRAID%20Common%20Files/8.02.21_MegaCLI.zip) .
#rpm -ivh Lib_Utils-1.00-09.noarch.rpm
#rpm -ivh MegaCli-8.02.21-1.noarch.rpm

Step:2. By default the utility is placed at location as below..
[root@server 8.02.21_Linux_MegaCLI]# cd /opt/MegaRAID/MegaCli/
[root@server MegaCli]# ls
install.log MegaCli64 MegaSAS.log

Step:3. Run the below command before adding the brand new disk drive.
[root@server MegaCli]# /opt/MegaRAID/MegaCli/MegaCli64 -PDList -aAll | grep -e “Enclosure Device ID” -e Slot
Enclosure Device ID: 252
Slot Number: 0
Enclosure Device ID: 252
Slot Number: 1

Step:4. Run the command again after injecting the new HDD in drive slot.
[root@server MegaCli]# /opt/MegaRAID/MegaCli/MegaCli64 -PDList -aAll | grep -e “Enclosure Device ID” -e Slot
Enclosure Device ID: 252
Slot Number: 0
Enclosure Device ID: 252
Slot Number: 1
Enclosure Device ID: 252
Slot Number: 3

Step:5. Now you have the following information the Enclosure Device ID: 252 and Slot Number: 3 for the newly added drive.

Step:6. Once added the new drive will be in foreign state. Give the below command to clear the foreign status.
[root@server MegaCli]#/opt/MegaRAID/MegaCli/MegaCli64 -CfgForeign -Clear -aALL

Step:7. Add the new drive to the desired RAID level by running below command.
#/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdAdd -r0 [252:3] -a0
Options:
-r1 = RAID1
252 = Enclosure Device ID
2 and 3 = Slot Number
-a0 = Adapter
In our case :
-r0 = RAID0
252 = Enclosure Device ID
3 = Slot Number
-a0 = Adapter

Step:8. tail the /var/log/messages for the new disk
sd 0:2:1:0: [sdb] Mode Sense: 1f 00 00 08
sd 0:2:1:0: [sdb] Write cache: enabled, read cache: enabled, doesn’t support DPO or FUA
sdb: sdb1 sdb2
sd 0:2:1:0: [sdb] Attached SCSI disk

Now you can use the new disk as any other normal drive.

Tuesday 18 September 2012


Find your IP Address on a Mac


Find your IP Address on a Mac

You can find your IP address from the Mac System Preferences:
  • From the Apple menu pull down “System Preferences”
  • Click on the “Network” preference pane
  • Your IP address will be visible to the right, as indicated in the screenshot below
ip address mac
Your IP address is the number listed, in the above case it is 192.168.0.100
Now we’ll cover the more technical approaches to getting your IP address using the Mac OS X command line:

Find your IP Address via the Mac OS X Terminal

This is how to find the IP address of your Mac through the Terminal, this is often the quickest way for those that are more technically inclined.
  • Launch the Terminal located in /Applications/Utilities/
  • Type the following command:
ifconfig |grep inet
  • You will see something that looks like this:
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
inet6 fe80::fa1e:dfff:feea:d544%en1 prefixlen 64 scopeid 0x5
inet 192.168.0.100 netmask 0xffffff00 broadcast 192.168.0.255

Monday 17 September 2012

Beginner's Introduction to Shell Script: PART 2

Beginner's Introduction to Shell Script: PART 1

Beginner's Introduction to Shell Script:PART 2
1. Beyond the Basics

1.1. Internal Variables:


Builtin variables:





variables affecting bash script behavior

$BASH
The path to the Bash binary itself

bash$ echo $BASH
/bin/bash

$BASH_ENV
An environmental variable pointing to a Bash startup file to be read when a script is invoked

$BASH_SUBSHELL
A variable indicating the subshell level. This is a new addition to Bash, version 3.
See Example 21-1 for usage.

$BASHPID
Process ID of the current instance of Bash. This is not the same as the $$ variable, but it often gives the same result.

bash4$ echo $$
11015


bash4$ echo $BASHPID
11015


bash4$ ps ax | grep bash4
11015 pts/2    R      0:00 bash4
       



$BASH_VERSION
The version of Bash installed on the system

bash$ echo $BASH_VERSION
3.2.25(1)-release

$HOME
Home directory of the user, usually /home/username

$HOSTNAME
The hostname command assigns the system host name at bootup in an init script. However, the gethostname() function sets the Bash internal variable$HOSTNAME.

$HOSTTYPE
host type
Like $MACHTYPE, identifies the system hardware.

bash$ echo $HOSTTYPE
i686

$MACHTYPE
machine type
Identifies the system hardware.

bash$ echo $MACHTYPE
i686

$OSTYPE
operating system type

bash$ echo $OSTYPE
linux

$PPID

The $PPID of a process is the process ID (pid) of its parent process. [2]
Compare this with the pidof command.(pidof -- find the process ID of a running program.)

$PROMPT_COMMAND
A variable holding a command to be executed just before the primary prompt, $PS1 is to be displayed.

$PS1
This is the main prompt, seen at the command-line.

$PS2
The secondary prompt, seen when additional input is expected. It displays as ">".

$PS3
The tertiary prompt, displayed in a select loop.

$PS4
The quartenary prompt, shown at the beginning of each line of output when invoking a script with the -x option. It displays as "+".

$PWD
Working directory (directory you are in at the time)
This is the analog to the pwd builtin command.

$UID
User ID number

The variables $ENV$LOGNAME$MAIL$TERM$USER, and $USERNAME are not Bash builtins


These are, however, often set asenvironmental variables in one of the Bash startup files. $SHELL, the name of the user's login shell, may be set from /etc/passwd or in an "init" script, and it is likewise not a Bash builtin.

sankar@new-host ~]$ echo $LOGNAME
sankar
[sankar@new-host ~]$ echo $SHELL
/bin/bash
[sankar@new-host ~]$ echo $TERM
xterm


Positional Parameters

$0$1$2, etc.
Positional parameters, passed from command line to script, passed to a function, or set to a variable..
$#
Number of command-line arguments [4] or positional parameters..
$*
All of the positional parameters, seen as a single word

Note"$*" must be quoted.
$@
Same as $*, but each parameter is a quoted string, that is, the parameters are passed on intact, without interpretation or expansion. This means, among other things, that each parameter in the argument list is seen as a separate word.

NoteOf course, "$@" should be quoted.

$?







Exit status of a command, function, or the script itself..

$$
Process ID (PID) of the script itself. The $$ variable often finds use in scripts to construct "unique" temp file names . This is usually simpler than invoking mktemp.

1.2. Typing variables: declare or typeset

 permit modifying the properties of variables. This is a very weak form of the typing.

declare/typeset options:


 -r readonly




(declare -r var1 works the same as readonly var1)

     declare -r var1=1
     echo "var1 = $var1"   # var1 = 1

  
 -i integer

declare -i number
# The script will treat subsequent occurrences of "number" as an integer.  

number=3
echo "Number = $number"     # Number = 3

-a array

declare -a indices

-f function(s)

    declare -f function_name


-x export









declare -x var3

This declares a variable as available for exporting outside the environment of the script itself.

-x var=$value

declare -x var3=373

NOTE:The declare command can be helpful in identifying variables, environmental..



bash$ declare | grep HOME
HOME=/home/bozo

bash$ zzy=68
bash$ declare | grep zzy
zzy=68


1.3. $RANDOM: generate random integer

   $RANDOM is an internal Bash function (not a constant) that returns a pseudo random integer in the range 0 - 32767. 

1.4. Manipulating Variables

Bash supports a surprising number of string manipulation operations.

2. Loops and Branches

2.1. Loops

for loops This is the basic looping construct.

Syntax: 
for arg  in [list] do   command(s)...  done
----------------
If do is on same line as for..
for arg  in [list] ; do 
Note: During each pass through the loop, arg takes on the value of each successive variable in the list.

The argument list may contain wild cards.


Example  Simple for loops
1. $vim sfloop.sh






#!/bin/bash
# Listing the planets.

for planet in Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto
do
  echo $planet  # Each planet on a separate line.
done


:wq


[sankar@new-host loops]$ chmod +x sfloop.sh
[sankar@new-host loops]$ ./sfloop.sh
Mercury
Venus
Earth
Mars
Jupiter
Saturn
Uranus
Neptune
Pluto

Each [list] element may contain multiple parameters. This is useful when processing parameters in groups.

2. Listing all users on the system.

$vim listallusers.sh

#!/bin/bash
# userlist.sh

PASSWORD_FILE=/etc/passwd
n=1           # User number

for name in $(awk 'BEGIN{FS=":"}{print $1}' < "$PASSWORD_FILE" )
# Field separator = :    ^^^^^^
# Print first field              ^^^^^^^^
# Get input from password file               ^^^^^^
do
  echo "USER #$n = $name"
  let "n += 1"
done  


# USER #1 = root
# USER #2 = bin
# USER #3 = daemon
# ...
# USER #30 = bozo

exit $?

#  Discussion:
#  ----------
#How is it that an ordinary user, or a script run by same,
#+ can read /etc/passwd? (Hint: Check the /etc/passwd file permissions.)
#  Isn't this a security hole? Why or why not?

:wq

2.3. Testing and Branching

case "$variable" in  

  "$condition1" ) 
 command... 
 ;;  
  "$condition2" ) 
 command... 
 ;;  

esac



Note
  • Quoting the variables is not mandatory, since word splitting does not take place.
  • Each test line ends with a right paren ).
  • Each condition block ends with a double semicolon ;;.
  • If a condition tests true, then the associated commands execute and the case block terminates.
  • The entire case block ends with an esac (case spelled backwards).
  • eg: $vim machinetype.sh
    case $( arch ) in   # $( arch ) returns machine architecture.
      ( i386 ) echo "80386-based machine";;
    # ^      ^
      ( i486 ) echo "80486-based machine";;
      ( i586 ) echo "Pentium-based machine";;
      ( i686 ) echo "Pentium2+-based machine";;
      (    * ) echo "Other type of machine";;
    esac
    
    
    :wq
    
    
    [sankar@new-host loops]$ ./machinetype.sh
    Pentium2+-based machine
    
    
    
    
    3. Arithmetic Expansion
    Arithmetic expansion provides a powerful tool for performing (integer) arithmetic operations in scripts. 
    
    
    z=`expr $z + 3`          # The 'expr' command performs the expansion.
    
    
    Arithmetic expansion with double parentheses, and using let
    
    
    z=$(($z+3))
    z=$((z+3))                                  #  Also correct.
                                                #  Within double parentheses,
                                                #+ parameter dereferencing
                                                #+ is optional.
    
    # $((EXPRESSION)) is arithmetic expansion.  #  Not to be confused with
                                                #+ command substitution.
    
    
    
    # You may also use operations within double parentheses without assignment.
    
      n=0
      echo "n = $n"                             # n = 0
    
      (( n += 1 ))                              # Increment.
    # (( $n += 1 )) is incorrect!
      echo "n = $n"                             # n = 1
    
    
    let z=z+3
    let "z += 3"  #  Quotes permit the use of spaces in variable assignment.
                  #  The 'let' operator actually performs arithmetic evaluation,
                  #+ rather than expansion.
    
    
    
    
    
    
    
    
    
    
    
    Beginner's Introduction to Shell Script: PART 3
    Beginner's Introduction to Shell Script: PART 4
    Beginner's Introduction to Shell Script: PART 5
    Beginner's Introduction to Shell Script: PART 6