Saturday, May 16, 2009

Solaris: Shell script to write output to a file

HiI need to run a sql query each day which retrieves data based on a numerical incremental (MAXID) value. I want then to store the max value from last query ran in a file (tempid) and then use this new number each day to retreive only the new data. Attached is a sample of the script being used.

#!/bin/sh

echo "Retrieve id"

FILE="/tmp/tempid"
MAXID=0

if [ ! -f $FILE ]; then
echo "$FILE : deos not exist"
exit 1
elif [ ! -r $FILE ]; then
echo "$FILE : can not read"
exit 2
fi

# read $FILE using the file descriptors
exec 3<&0 #save standard input
exec 0<$FILE
while read line
do

MAXID=$line

done

#
# Query
#

sh -c "sqlplus etc ................ <

spool /tmp/temp.csv

Friday, May 15, 2009

Check Oracle Version

There are several ways where you can query or retrieve the version number of installed Oracle products:

1. If you just want to check the version information of the Oracle database, simply connect and login to the Oracle database with SQL *Plus. Upon login, you will see:

SQL*Plus: Release 9.2.0.6.0 - Production on Tue Oct 18 17:58:57 2005

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.6.0 - Production

The first italic number is the version of the SQL*Plus client and the second italic number is the version of Oracle database which you are connected to .



2. Retrieve the version information from v$version table by using SQL*Plus. In this table you can find version information on Oracle, PL/SQL, etc.

To retrieve the version information for Oracle, you execute the following SQL statement:

select * from v$version where banner like ‘Oracle%’;

It should return something like this:

Banner
————————————————————————————–
Oracle9i Enterprise Edition Release 9.2.0.1.0 - 64bit Production



3. Version information can also be checked from Installed Products from the Oracle Universal Installer. It will tells you what products is installed on the machine and also its version information too.

In Unix, the installer is located at $ORACLE_HOME/bin/runInstaller.
In Windows, access the installer by Start -> All Programs -> Oracle Installed Products -> Universal Installer.

renaming multiple files in Solaris

If those are the only 3 files ending in .log in your directory, you could do this:

for i in `ls *.log`;do
mv $i $i.bak
done

That would do each one individually but loop through the 3 files so you only have to do the one command.

About

Blogger templates