Category Archives: Mac OS

grep lines having a text string from compressed files

The log of an application in my job is archived in a file, 1 file per day. I was requested to extract the activity of one client from these logs for the whole August, i.e., from 31 compressed files.

I placed all compressed log files into a folder called /database and I created a file zgrep_all.sh to search and extract the log lines of my client. (If your *.gz  files are located somewhere else then pay attention to line 11 of tje script and modify it properly)

#!/bin/bash

# author: tomeu.mir
# filename: zgrep_all.sh
# desc  : search string in all *gz files and spools the output to a file
# usage : . zgrep_all.sh <search string> <output filename>
#   
search_string=$1
output_file=$2

for f in database/*.gz
do
  now=$(date +”%Y/%m/%d %T”)
  echo “[$now] Processing $f file with search string $search_string and output file $output_file”   
  zgrep -i “$search_string” $f >>  $output_file
done
now=$(date +”%Y/%m/%d %T”)
echo “[$now] done.”

Finally I executed the following:

$ . zgrep_all.sh MYCLIENTNAME output.log

Advertisements

SQLDeveloper. Change the IDE language and font size

First you have to shutdown your SQLDEveloper.

IDE language

Edit the file sqldeveloper.conf for changing the IDE language adding the following lines:

# Tomeu Mir – forcing English UI language
AddVMOption -Duser.language=en
AddVMOption -Duser.country=UK

The location of the sqldeveloper.conf is at /Applications/SQLDeveloper.app/Contents/Resources/sqldeveloper/sqldeveloper/bin

IDE Font Size

Edit the file ide.properties for setting the desired font size of the IDE. Comment any line like Ide.FontSize.* and add the following one:

Ide.FontSize=10

For finding the location of the ide.property file you can do the following from a shell command and choose the one corresponding to the highest edition.

$ cd ~/.sqldeveloper/
.sqldeveloper$  find . -name “ide.properties”
./system3.2.20.09.87/o.sqldeveloper.11.2.0.9.87/ide.properties
./system4.0.3.16.84/o.sqldeveloper.12.2.0.16.84/ide.properties

Now you can restart your SQLDeveloper and enjoy working again.

How to install an Oracle Database on your MacBook

The best way I have found for installing an Oracle Database (EE 12c) on you MacBook is installing a Database Virtual Box Appliance / Virtual Machine.

Main steps are:

  1. Install Oracle VM VirtualBox Manager

You can download it from https://www.virtualbox.org/ and the installation is very simple.

  1. Download the VM appliance from Oracle

I recommend to use a download manager as I failed twice just trying to download it as a normal file using Chrome. I installed DownThemAll from http://www.downthemall.net/ (note: it requires Firefox). The OVA file can be downloaded from: http://www.oracle.com/technetwork/database/enterprise-edition/databaseappdev-vm-161299.html

  1. Create the Virtual Machine.

Open VM Virtual Box and go to File/Import appliance. Then select the file that you have download and just go forwards.

And that’s all. Everything is installed.

Start working with your database

Now you should start the VM for starting using your database. Then you will be ready to make a client connection from you Mac, either using a tnsnames entry as follows:

MYMAC_DB =

(DESCRIPTION=

(ADDRESS= (PROTOCOL=TCP) (HOST=127.0.0.1) (PORT=1521) )

(CONNECT_DATA= (SERVER=dedicated) (SERVICE_NAME=cdb1) )

)

Or using a jdbc connection string like jdbc:oracle:thin:@127.0.0.1:1521/PDB1

All passwords are oracle (including user sys).

For being able to share files between your Mac and the Oracle VM you can enable the drag and drop option in the Oracle VM VirtualBox Manager. Select the VM created, click on Settings. A new window will pop up. In the General screen you will find where to set up the Shared ClipBoard and the Drag & Drop in the tab Advanced.

Latest note: this should not be used for creating an environment for developers, testers, etc. And off course if you are thinking about a production environment just forget it.

How to install Tomcat in Mac OS

How to install Tomcat in Mac OS

 1. Check that java is installed in your computer

By default MAC comes with java installed, you do not have to do anything special expect that you want an specific java version running.

Open a Terminal and do the check:

$ java -version

java version “1.6.0_51”

Java(TM) SE Runtime Environment (build 1.6.0_51-b11-457-11M4509)

Java HotSpot(TM) 64-Bit Server VM (build 20.51-b01-457, mixed mode)

2. Download the apache tomcat

Tomcat is software that permits a web request to be directed to a piece of Java code (servlet) with some associated infrastruture to handle cookies and request/reply coordination. These functions are collectively referred to as a “web container”.   Tomcat used to also be referred to as Catalina. The Catalina name is still used in some of the config setup below

 Download Tomcat 7 Binary Distribution Core (tar.gz) from the Apache Tomcat 7 Downloads Page and uncompress it into a directory of your choice.

Copy the files to your /usr/local folder:

$ sudo mv /Users/<your_user>/Downloads/apache-tomcat-7.0.53.tar.gz /usr/local

Uncompress the downloaded file:

$ sudo gnutar -xzvf apache-tomcat-7.0.53.tar.gz

Now you are ready to startup, use and shutdown yout Toncat server:

$ cd apache-tomcat-7.0.53/bin/

$ ./startup.sh

At this point you can test that your sever is up and running from a navigator with http://localhost:8080/

You can shutdown the server just typing:

$ ./shutdown.sh

3. Set the environment variables

Edit the bash profile with an editor like vi and add the following lines:

$ sudo vi ~/.bash_profile

# Tomcat entries

export CATALINA_BASE=”/usr/local/apache-tomcat-7.0.53″

export CATALINA_HOME=”/usr/local/apache-tomcat-7.0.53″

export CATALINA_TMPDIR=”/usr/local/apache-tomcat-7.0.53/temp”

Save it and reload the bash profile:

$ . ~/.bash_profile

4. Deploy and test an application

copy or deploy your test application with its own folder in /usr/local/apache-tomcat-7.0.53/webapps/myTestApp

Open a navigator and type test your URL: http://localhost/myTestApp/myIndex.jsp

How to install Oracle SQLPlus and Oracle Client in MAC OS

Hi,

The How To has been extracted from the following link: http://www.joelennon.ie/2014/02/06/installing-oracle-instant-client-mac-os-x/

I just skipped some text and modified some paths to adapt it to oracle client 11.2.0.4 release.

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

1. Download the files from the Oracle Site

http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html

Be sure to grab the following two files:

  • Instant Client Package – Basic
  • Instant Client Package – SQL*Plus

2. Extract the files and create the proper folder structure.

Open a Terminal window and unzip the downloaded files.

$ unzip -qq instantclient-basic-macos.x64-11.2.0.4.0.zip

$ unzip -qq instantclient-sqlplus-macos.x64-11.2.0.4.0.zip

Note: The -qq flag will tell the unzip utility to run in quieter mode, preventing any output from being displayed on the screen.

By default, the archive will extract all these files to a single directory. Instead, we’ll create a nicely structured directory to keep these files in your user Applications folder.

$ mkdir -p /Applications/oracle/product/instantclient_64/11.2.0.4.0/bin

$ mkdir -p /Applications/oracle/product/instantclient_64/11.2.0.4.0/lib

$ mkdir -p /Applications/oracle/product/instantclient_64/11.2.0.4.0/jdbc/lib

$ mkdir -p /Applications/oracle/product/instantclient_64/11.2.0.4.0/rdbms/jlib

$ mkdir -p /Applications/oracle/product/instantclient_64/11.2.0.4.0/sqlplus/admin

$ mkdir -p /Applications/oracle/product/instantclient_64/11.2.0.4.0/network/admin

Next, move the files over to these directories as follows:

$ cd instantclient_11_2

$ mv ojdbc* /Applications/oracle/product/instantclient_64/11.2.0.4.0/jdbc/lib/

$ mv x*.jar /Applications/oracle/product/instantclient_64/11.2.0.4.0/rdbms/jlib/

$ mv glogin.sql /Applications/oracle/product/instantclient_64/11.2.0.4.0/sqlplus/admin/

$ mv *dylib* /Applications/oracle/product/instantclient_64/11.2.0.4.0/lib/

$ mv *README /Applications/oracle/product/instantclient_64/11.2.0.4.0/

$ mv * /Applications/oracle/product/instantclient_64/11.2.0.4.0/bin/

3. Create a proper tnsnames.ora file to define proper connection strings

Copy or create a tnsnames.ora file to /Applications/oracle/product/instantclient_64/11.2.0.4.0/network/admin/

Example:

Create the tnsnames.ora file with the vi editor, paste the following lines and save it.

MYDB=

  (DESCRIPTION=

    (ADDRESS=

      (PROTOCOL=TCP)

      (HOST=*********)

      (PORT=1521)

    )

    (CONNECT_DATA=

      (SERVER=dedicated)

      (SID=MYDB-SID)

    )  )

(You can better ask to a DBA to review the content of this file and ask her to provide you with a proper test connection)

4. Set up environment variables

Edit or create a file .bash_profile

$ cd /Users/UserName

$ vi ~/.bash_profile

if you haven’t created a .bash_profile before the file will be empty, otherwise just add the following lines to the end of the existing file.

export ORACLE_HOME=/Applications/oracle/product/instantclient_64/11.2.0.4.0

export PATH=$ORACLE_HOME/bin:$PATH

export DYLD_LIBRARY_PATH=$ORACLE_HOME/lib

To load this profile, run the following command:

$ source ~/.bash_profile

Assuming you have set up your tnsnames.ora file correctly, you should now be able to connect one of the databases as follows:

5. Start using SQLPlus

$ sqlplus username/password@database

6. Did you enjoy? That’s all folks.

🙂

**********************************

Fixing command history for using SQLPlus line edition with arrow keys

If you have used the command-line SQLPlus in a Windows environment, you will probably be used to using the command history to execute previous SQL statements using the arrow keys. One thing you’ll notice in SQLPlus for the Mac is that this doesn’t work by default, if you hit the up key you’ll see a strange character sequence ^[[A rather than the previous command. Let’s go ahead and fix this now.

To do this, you’ll need to use rlwrap. You could download this from source and build it yourself, but I find it much easier to use the fantastic brew package manager for Mac OS X. Head over to http://brew.sh/ and follow the instructions to install and set up Homebrew (it’s very easy). With Homebrew installed, you can now easily install rlwrap on your system with one command:

$ ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

$ brew install rlwrap

The final thing you need to do is tell your system to use rlwrap whenever you use SQL*Plus. To do that, you’ll need to edit your .bash_profile file again.

$ vi ~/.bash_profile

Add the following line to the end of the file.

alias sqlplus=’rlwrap sqlplus’

Now reload the .bash_profile:

$ source ~/.bash_profile

Now, when you launch SQL*Plus and try to use the arrow keys to access previous commands, it will work.

Apache server on Mac OS

Manage the Apache server

Terminal Commands

  • Starting:  $sudo apachectl start
  • Stopping: $sudo apachectl stop
  • Restarting: $sudo apachectl restart

Adding the Web Sharing option in Systems Preferences:
http://clickontyler.com/blog/2012/02/web-sharing-mountain-lion/

Configuring Sites folder

http://www.maketecheasier.com/setup-web-server-in-mountain-lion/

By default, Apache serves files that are in the folder location “/Library/WebServer/Documents”.
On a multiple users system, you can setup the web server to serve files for different users
using the URL “http://localhost/~tomeu.mir“.

1. create a folder Sites in /Users/tomeu.mir
$mkdir /Users/tomeu.mir/Sites

2. create a tomeu.mir.conf file in the apache server users folder:
$sudo vi /etc/apache2/users/tomeu.mir.conf

and copy and paste the following code to the conf file.

<Directory “/Users/tomeu.mir/Sites/”>
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>

3. test it

create a test html file and place it in /Users/tomeu.mir/Sites/

$cd /Users/tomeu.mir/Sites/
$vi myTest.html

insert your html test code and save it.

<html><body><h1>My site works cojones</h1></body></html>

Go to your browser and type: http://localhost/~tomeu.mir/myTest.html