Thursday, November 22, 2012

Starting Postgress SQL


Install It
apt-get install postgresql-9.1

Create a user
sudo -u postgres createuser -d -R -P

Give a password for the user.
sudo -su postgres

postgres$  psql -U postgres

ALTER USER postgres with password 'secure-password';

now you can directly connect from Super User like this
psql -U postgres -h localhost


Create a database

createdb mydb


Export from one db to another
pg_dump -C -h localhost -U localuser dbname | psql -h remotehost -U remoteuser 
Take a dump
pg_dump -c -U postgres ${fromDataBase} -f ABIMS9JAN13tabledump.sql -h ${fromHost}
Execute the dump
psql -d ${toDataBase} -f dumpfilename.sql -h ${toHost} -U postgres -w password




Install GUI
sudo apt-get install pgadmin3

pgadmin3

pg_dump --username "postgres" -Fc origin > origin.dump


pg_restore --username "postgres" -d target origin.dump

Friday, October 19, 2012

Which Process Running on What Port

http://www.debian-administration.org/articles/184



To see all the ports open for listening upon the current host you can use another command netstat (contained in the net-tools package):
root@mystery:~# netstat -a |grep LISTEN |grep -v unix



Which process is bound to port 80

lsof -i :80

Friday, October 12, 2012

Installed Packages and Locations?


What is installed ?
       $ dpkg --get-selections
       or
       $ dpkg --list  
       or
       $ dpkg --list | grep -i 'gradle'

Location installed ?
       $ dpkg -L gradle

To Remove ?
       $ sudo apt-get --purge remove lighttpd

Wednesday, September 26, 2012

Find a file in Debian

 find /usr -name java

--find under the folder /user the name java. Can use wild cards like *.txt etc etc.

Setting Oracle's Java instead of Open JDK in Debeian based distributions


  1. Enter sudo add-apt-repository ppa:webupd8team/java to add the partner repository.
  2. Enter sudo apt-get update to update the source list.
  3. Enter sudo apt-get install oracle-java7-installer

Thursday, September 20, 2012

Installing Oracle 11gXE in Linux Mint Mate 12

I followed this article, and it helped a lot!

http://mikesmithers.wordpress.com/2011/11/26/installing-oracle-11gxe-on-mint-and-ubuntu/

Note that, Oracle 11g XE Does not support debeian based package installers, hence I ran into many difficulties, but eventually managed to install successfully.

Installing Oracle XE 11g Release 2 was extremely successful in Debian Squeezy OS.

These are the basic steps I followed.

1. First download and unzip the RPM.

   
   unzip oracle-xe-11.2.0.1.0.x86_64.rpm.zip


2. Convert the RPM to DEB.


  sudo alien --scripts oracle-xe-11.2.0-1.0.x86_64.rpm

3. Install this Lib. In Debian Squeeze, I had to add an entry to the /etc/sources after having searched for the libaio1 from the net for debian. 

  sudo apt-get install alien libaio1

4.  Create the chkconfig file.

      cd /sbin

      vi chkconfig

#!/bin/bash
# Oracle 11gR2 XE installer chkconfig hack for Debian by Dude
file=/etc/init.d/oracle-xe
if [[ ! `tail -n1 $file | grep INIT` ]]; then
   echo >> $file
   echo '### BEGIN INIT INFO' >> $file
   echo '# Provides:             OracleXE' >> $file
   echo '# Required-Start:       $remote_fs $syslog' >> $file
   echo '# Required-Stop:        $remote_fs $syslog' >> $file
   echo '# Default-Start:        2 3 4 5' >> $file
   echo '# Default-Stop:         0 1 6' >> $file
   echo '# Short-Description:    Oracle 11g Express Edition' >> $file
   echo '### END INIT INFO' >> $file
fi
update-rc.d oracle-xe defaults 80 01

sudo chmod 755 chkconfig

5.  sudo ln -s /usr/bin/awk /bin/awk


6. 

Now you need to set the shared memory file system which oracle uses
mount -t tmpfs shmfs -o size=2048m /dev/shm

df-h should return the below result
shmfs           2.0G  1.2M  2.0G   1% /dev/shm



if this failed unlink /dev/shm

sudo unlink /dev/shm
sudo mkdir /dev/shm
sudo mount -t tmpfs shmfs -o size=2048m /dev/shm



7. dpkg --install ./oracle-xe_11.2.0-2_amd64.deb 

8.grep /var/lock/subsys /etc/init.d/oracle-xe

9    sed -i 's,/var/lock/subsys,/var/lock,'/etc/init.d/oracle-xe

10.
      sudo usermod -a -G dba oracle
sudo usermod -a -G dba mike



11. Make sure these environment variables are set for all users

export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe export ORACLE_SID=XE
export NLS_LANG=`$ORACLE_HOME/bin/nls_lang.sh` export PATH=$ORACLE_HOME/bin:$PATH

You can execute the script given by oracle, located in:
/u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh

or add the above line to the of /etc/bash.bashrc



Note: when you switch to oracle user:
i.e. su - oracle, make sure the environment variables are still set.


12. /etc/init.d/oracle-xe configure

If oracle didnt start successfully, i.e if you didn't get the output shown in the end of this blog, do the following

su - oracle


./u01/app/oracle/product/11.2.0/xe/bin/lsnctrl

start


These are the only changes I made in the sequence mentioned above.
Oracle started successfully, and was able to connect and create tables etc etc.



byorn@boogy /etc/init.d $ sudo ./oracle-xe status LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 23-SEP-2012 18:16:47 Copyright (c) 1991, 2011, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.2.0 - Production Start Date 23-SEP-2012 18:16:18 Uptime 0 days 0 hr. 0 min. 29 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Default Service XE Listener Parameter File /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora Listener Log File /u01/app/oracle/diag/tnslsnr/boogy/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=boogy)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=boogy)(PORT=8080))(Presentation=HTTP)(Session=RAW)) Services Summary... Service "PLSExtProc" has 1 instance(s). Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service... Service "XE" has 1 instance(s). Instance "XE", status READY, has 1 handler(s) for this service... Service "XEXDB" has 1 instance(s). Instance "XE", status READY, has 1 handler(s) for this service... The command completed successfully



Note: When I restarted my machine, oracle failed because df-h didnt show me the newly created shared memory file system.
For that i shut down oracle completely, and executed the steps in 6. and started again, all went fine.






Friday, September 7, 2012

Setting Environment Variables - Ubuntu/Mint


This page describes the process of setting up environment variables in Ubuntu.

session-wide environment variables

In order to set environment variables in a way that affects a user’s entire desktop session, one may place commands to set their values in one of the “hidden” script files in the user’s home directory. The more common such files are outlined below.
  • ~/.profile – This is probably the best file for placing environment variable assignments in, since it gets executed automatically by the Display Manager during the startup process desktop session as well as by the login shell when one logs-in from the textual console.
  • ~/.bash_profile or ~./bash_login – If one of these file exist, bash executes it rather then “~/.profile” when it is started as a login shell. (Bash will prefer “~/.bash_profile” to “~/.bash_login”). However, these files won’t influence a graphical session by default.
  • ~/.bashrc – Because of the way Ubuntu currently sets up the various script files by default, this may be the easiest place to set variables in. The default configuration nearly guarantees that this file will be executed in each and every invocation of bash as well as while logging in to the graphical environment. However, performance-wise this may not be the best thing to do since it will cause values to be unnecessarily set many times.

system-wide environment variables

Environment variable settings that affect the system as a whole (rather then just a particular user’s desktop session) can be placed in any of the many system-level scripts that get executed when the system or the desktop session are loaded. Ubuntu defines several locations dedicated to placing such settings:
  • /etc/profile – This file gets executed whenever a bash login shell is entered (e.g. when logging in from the console or over ssh), as well well as by the DisplayManager when the desktop session loads. This is probably the file you will get referred to when asking veteran UNIX system administrators about environment variables. In Ubuntu, however, this file does little more then invoke the /etc/bash.bashrc file.
  • /etc/bash.bashrc – This is is the system-wide version of the ~/.bashrc file. Ubuntu is configured by default to execute this file whenever a user enters a shell or the desktop environment.
  • /etc/environment – This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line. Specifically, this file stores the system-wide locale and path settings.
The above was taken from the following URL: https://help.ubuntu.com/community/EnvironmentVariables

Tuesday, August 14, 2012

Binding with JAXB


1) Get a xsd from an xml.
http://www.freeformatter.com/xsd-generator.html#ad-output


2) Generate the Java Objects
xjc.sh -p com.package.name books.xsd -d workfolder


3) Process it in Java

        JAXBContext jc = JAXBContext.newInstance("com.package.name");
   
 Unmarshaller unmarshaller = jc.createUnmarshaller();
   
 Collection collection = (Collection) unmarshaller.unmarshal(new File("src/books.xml"));



Wednesday, August 8, 2012

Git Bare Repo - Concept Summary

Do you get the below error: on GIT PUSH ?????

remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.


Understand the concept: : )



Notice 1, 2, 3, 4

2 - is the bare repo

To update the source of truth repo, you have to pull

To update the shared repo from the working , you have to push to it.

Sunday, August 5, 2012

Groovy Patterns - I just forget!


 http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html



def thePattern = /foo/
def theString = "boo foo";
def theMatcher = theString=~thePattern


//1.
//it's "true" if it has at least one match,
if( theString =~ thePattern){
println "true";
}else{
println "false"
}


//2.
//print the the matcher to see
println theMatcher;
//note theMatcher is an array
println theMatcher[0];


//3
def stringToMatch = '''abc quick brownfox ? blah blah'''

def myPattern = /blah/

def m = stringToMatch=~myPattern
println m[0] + m.size()

Thursday, July 5, 2012

Debian file permissions

list file permissions with ls -l

-  rwx   r_x    _wx
 

  • The first "-"  says the file type. d|f|s (directory, file, or symlink)
  • The next three chars "rwx" are the privileges for the user
  • And the next "r_x" are the privileges for the group.
  • "_wx" are the privileges for others

Note the "_"  means denied. or not set.

chmod u-r myfile means , remove read privileges from the user.

e.g.
nano myfile.
touch myfile.
echo "blah" >> myfile
cat myfile.

Restore Xorg.conf file in Debian/Mint/Ubuntu (Dual Monitor configuration in mint)


Heres what happend, I edited the xorg.conf file and when I restarted my PC, i got blank screens in both my monitors.

How I resolved it:?

1) Booted my PC with a Bootalble Linux Live Mint CD (same as OS),
2) Type "gparted"  into the filter text box  of the start menu or in terminal  window.
3) Once the partitions window is open , locate the partition name  that points to your hard drive's Linux partition.
Most probably it will be marked with /ext4/ . You should be able to figure it out, by looking at the details in 'gparted.'
4) Now mount it:  type: sudo mount /dev/sda1 /mnt  (Note: My mount location was /dev/sda1,..yours may be different)
5) cd /mnt/etc/x116) create a default xorg.conf file with the following content.
     
        Section "Device"
        Identifier      "Default Device"
        Option  "NoLogo"        "True"
        EndSection

7) Restart your machine everything should be fine.8) If you want dual monitor configuration, type NVedia X Server in the Start filter box, and use that application to configure your second monitor.Cheers.

Sunday, June 17, 2012

Quick Start C++ in Linux Mint/Ubuntu/Debian Hello World

1) Install C and C++ Compilers in Mint 

      sudo aptitude install build-essential 


2) Compile the first Program sudo gedit first.c add the following lines save and exit the file



            #include int main() { printf("Hello world\n"); return 0; } 


3) Firstly compile the code using the following command 

     cc -c first.c 
 that would produce an object file you may need to add to the library.


 4) then create an executable using the following command 

 cc -o first first.c


 5) Now run this executable using the following command

 ./first

Tuesday, January 31, 2012

Fix Broken Packages

Debian, fix broken package installations sudo apt-get -f install Running a .DEB file sudo dpkg -i skype-ubuntu_2.2.0.35-1_amd64.deb