Monday, August 31, 2009

Accessing database Using Shell Script

Here i m going to tell u how can u access the database (mysql,Oracle ) using shell script in linux..

for mysql..

u need to install mysql on your linux distros..

after that as usual write a shell script to access database in user interactive mode..

running script example is...

#!/bin/bash
1 read -p "enter mysql user name:" name
2 stty -echo #echo off
3 read -p "enter mysql passwd :" password
4 stty echo #echo on
5 mysql -u $name -p$password<<END
6 use databasename;
7 select * from tablename
8 END

it asks user for mysql user name and password..then may asks for some pattern,input to search in database and finish with the desired result to the user.

NOTE: If there is no user name and password set for mysql..then skip first for lines of script and replace fifth line with

mysql <<END

also note that there is no space between -p and password provided by the user.



For Oracle10g XE(Express Edition) :


you need to install Oracle10g XE on your linux distros..

you may refer this link to installing on ubuntu..

if you are ready with your installation..
after that as usual write a shell script to access database in user interactive mode..

https://help.ubuntu.com/community/Oracle10g

running script example is...

#!/bin/bash
1 read -p "enter oracle user name:" name
2 stty -echo #echo off
3 read -p "enter mysql passwd :" password
4 stty echo #echo on
5 sqlplus $name/$password<<END
6 select * from tablename;
7 END

it asks user for oracle user name ( generally system )and password..then may asks for some pattern,input to search in database and finish with the desired result to the user.

Thank you............

1 comment:

  1. //for small image

    fileName = dirInfo.GetFiles("*.jpg").ElementAt(3).ToString();
    img = Image.FromFile("C:\\Users\\v-ramaki\\Pictures\\" + fileName);
    finalImg = new Bitmap(img, 40, 48);
    gfx = Graphics.FromImage(img);
    gfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
    pictureBox4.Image = null;
    pictureBox4.SizeMode = PictureBoxSizeMode.CenterImage;
    pictureBox4.Image = finalImg;


    // for largaer image

    fileName = dirInfo.GetFiles("*.jpg").ElementAt(3).ToString();
    img = Image.FromFile("C:\\Users\\v-ramaki\\Pictures\\" + fileName);
    finalImg = new Bitmap(img, 56, 70);
    gfx = Graphics.FromImage(img);
    gfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
    pictureBox4.Image = null;
    pictureBox4.SizeMode = PictureBoxSizeMode.CenterImage;
    pictureBox4.Image = finalImg;

    ReplyDelete