Archive

Posts Tagged ‘Linux’

How to rebuild Ubuntu package from the sources

January 7th, 2010 Michael Stepanov No comments

There are two ways (at least) to rebuild Ubuntu package from the source.
Using Ubuntu diff file and dpkg-buildpackage

  • Download source from Ubuntu repository.
  • Download Ubuntu diff file and apply it:
    patch -p1 < ubuntu.diff
  • Build package:
    dpkg-buildpackage -rfakeroot

Using .dsc file and debuild

  • Download .dsc file
  • Run following command:
    dpkg-source -x file.dsc

    Note, sometimes the archive with sources should be presented in the same directory!

  • Go to source directory and start building:
    debuild

In both cases the development packages should be installed first:

sudo apt-get install build-essential devscripts

Categories: Linux Tags: , , ,

Fixing GRUB bootloader on dual-boot PC

December 11th, 2009 Michael Stepanov No comments

I have two versions of LinuxMCE on my HTPC – stable 0710 and developer 0810. The 0810 was installed after 0710. So, the GRUB bootloader was placed on 0810 partition. A few days ago I decided re-install 0810 from the scratch and I deleted its partition including GRUB booloader. As result I couldn’t boot 0710 anymore. Thanks to GRUB power and flexibility I was able to fix that problem and watch Champions League :) The solution is simple and clear: boot from any LiveCD, drop terminal and type following command there:

sudo grub
>root (hd0,0)
>setup (hd0)

That’s it. After booting from HDD the GRUB menu was found again.

Categories: Linux Tags: , , ,

Log for Mysql console session

December 4th, 2009 Michael Stepanov No comments

To log Mysql console session use option –tee (two dashes!) with full path to the log file:

mysql -uroot my_db –tee=/tmp/mysql_console.log

As result the file /tmp/mysql_console.log will contains all commands and queries with result of their executions. That might be helpful to keep your queries for using next time or for troubleshooting.

The author of the post, where I found that useful info, said that each time the Mysql session is started with logging the log file will be replaced. In my case it isn’t. As I expected the new messages just are appended to the log file.

Categories: Digital Life, Linux Tags: , , ,

VIM and Mysql integration

November 27th, 2009 Michael Stepanov No comments

I use VIM with additional configuration instead of IDE. That configuration includes code explorer using ctag, syntax checking for PHP and Perl and run Perl scripts (syntax highlighting is not a subject of discussion ;) ). Also I should run Mysql queries often. So, I decided to add integration with Mysql to VIM. I managed to do that thanks to that simple solution. Just add this code to your .vimrc:
to select database:

map <C-d> :call SwitchDB()<CR>
:function SwitchDB()
: let g:current_db = input(“Database > “)
:endfunction

to run query:

map <C-m> :call Doquery()<CR>
:function Doquery()
: if !exists(“g:current_db”)
: call SwitchDB()
: endif
: let query_string = input(g:current_db . ” > ” )
: if query_string != “”
: exe “!mysql ” . g:current_db . ” -e \”" . escape(query_string, ‘”‘) . “\”"
: endif
:endfunction

So, when you press Ctrl-d the VIM gives you a prompt to type database name, Ctrl-m will run query. Sure you can use the your preferable combinations of keys. Also you may extend the login functionality by adding prompt for database host and user or hardcoded that information in the SwitchDB() function.

Using VIM to construct queries in the Mysql shell even much easier. Just specify VIM as default editor:

export EDITOR=vim

After that type \e in the Mysql shell. It’ll bring you VIM window where you’ll able to type your query. To finish with editing just type ZZ as usual. To run built query type ; and press Enter.

As result we’ll have possibility to run Mysql queries directly from VIM and using VIM to create queries in the Mysql shell.

Categories: Digital Life, Linux Tags: , , ,

Add history and auto-complete to the SQL*Plus

September 25th, 2009 Michael Stepanov No comments

I was very surprised how pure the Oracle’s command line utility SQL*Plus. Comparing with mysql it lack history, completion and doesn’t allow even edit query. To fix that the utility rlwrap can be used. I installed it via yum under Fedora 11 and run like that:

rlwrap sqlplus db_user@db

To have auto-complete feature you should find file SQL.dict somewhere (drop the comment, please, if you know the place). It contains SQL keywords, functions and commands. The command to run SQL*Plus will be following in that case:

rlwrap -b “” -f $HOME/sql.dict sqlplus db_user@db

To make our life easier we can create an alias in the .bash_profile or .profile:

alias mysqlplus=’rlwrap -b “” -f $HOME/sql.dict sqlplus’

There is an another interesting improvement for Linux users – using VIM as default editor of SQL*Plus. I didn’t try it practically yet.

[via Oracle Online]

Categories: Linux Tags: , ,

Oracle date format and Perl

September 24th, 2009 Michael Stepanov No comments

Oracle has its own date format – DD-MM-YY (24-sep-09). So, to insert a value into Oracle date field you should somehow convert date from your format. Sure it can be done using some date/time module or your own function. But there are two simpler ways – set desire date/time format for session or use Oracle date conversion function.

To set specific date/time format for the session just run following query right after connection:

  1. ALTER SESSION SET NLS_DATE_FORMAT = ‘YYYY-MM-DD HH24:MI:SS’

After that you may insert date such 2009-09-24 without any problems.

Another way is convert date to the Oracle format inside the query:

  1. INSERT INTO some_table (d_start) VALUES (TO_DATE(‘2009-09-24 11:12:00′, ‘YYYY-MM-DD HH24:MI:SS’))

Both approaches work fine. But the first one is more appropriate if you use placeholders in your query.

Categories: Perl Stuff Tags: , ,

Connect to Oracle DB from Perl script

September 23rd, 2009 Michael Stepanov No comments

After successful installation of DBD::Oracle it’s time to use it. The connection string is the same as for he rest DB:

  1. my $dbi = DBI->connect("dbi:Oracle:$db_name:$db_host:$db_port", $db_user, $db_pass);

As result of running code above I got following error:

Couldn’t connect to database db_name: ORA-12154: TNS:could not resolve the connect identifier specified (DBD ERROR: OCIServerAttach)

After googling I found that the problem was that. I tried to connect to the remove database but the driver couldn’t do that without special file – tnsnames.ora. It should be placed to the $ORACLE_HOME/network/admin and contain something like that:

  1. db_name =
  2.  (DESCRIPTION =
  3.    (ADDRESS_LIST =
  4.      (ADDRESS = (PROTOCOL = TCP)(HOST = db_host)(PORT = db_port))
  5.    )
  6.  (CONNECT_DATA =
  7.    (SERVICE_NAME = db_name)
  8.  )
  9. )

And the connection string should be changed to use service name from the tnsnames.ora instead of host:

  1. my $dbi = DBI->connect("dbi:Oracle:$service_name", $db_user, $db_pass);

Finally we should export variable ORACLE_SID into our environment. Add this command into .bashrc

  1. export ORACLE_SID="orcl"

or set it using Perl variable $ENV:

  1. $ENV{ORACLE_SID} = ‘orcl’;

See also

Categories: Perl Stuff Tags: , , ,

Installing DBD::Oracle under Fedora 11

September 23rd, 2009 Michael Stepanov No comments

Recently I got a task which needs to communicate with database Oracle from Perl. Perl has an excellent database abstraction interface DBI. But for specific database it needs a driver – DBD module. To install DBD::Oracle you have to perform following simple steps:

  1. Download and install oracle-instantclient11.2-basic and oracle-instantclient11.2-devel RPMs from Instant Client Downloads for Linux x86 page.
  2. Export ORACLE_HOME:
    export ORACLE_HOME=/usr/lib/oracle/11.2/client/
  3. Install DBD::Oracle using cpan shell or manually.

The most difficult part for me was installing Oracle client. Because navigation on the Oracle web site is not clear. Additionally you can install SQL*Plus package (oracle-instantclient11.2-sqlplus) to use Oracle shell for testing.

The RedHat Enterprise and CentOS users can use Perl-DBD-Oracle RPM to avoid separate Oracle client installation.

Categories: Perl Stuff Tags: , , , ,
Get Adobe Flash playerPlugin by wpburn.com wordpress themes