How to know sqlplus version from inside sqlplus - sqlplus

I am offered (by some framework) to run commands in sqlplus, but am not launching it myself.
I'd like to know the version of that sqlplus running.

Within SQL*Plus, there are some preDEFINEd substitution variable:
SQL> define
DEFINE _DATE = "23-NOV-13" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "" (CHAR)
DEFINE _USER = "" (CHAR)
DEFINE _PRIVILEGE = "" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1102000100" (CHAR)
DEFINE _EDITOR = "Notepad" (CHAR)
Notice the _SQLPLUS_RELEASE. You reference this in SQLPLUS.
For example, you can do something like:
sqlplus -S /nolog<<EOF
prompt &_SQLPLUS_RELEASE
quit
EOF

You can just use command :
sqlplus -V
And you should get :
SQL*Plus: Release 18.0.0.0.0 - Production
Version 18.3.0.0.0
Or :
SQL*Plus: Release 19.0.0.0.0 - Production
Version 19.12.0.0.0

I don't think you can with an actual query. You may be able to get it with this:
SELECT
PROGRAM, MODULE
from v$session s
order by s.sid;
The Module column may contain the version number, it might not. It depends on the program. If memory serves correctly, sqlplus does not give this. For example, TOAD gives "TOAD Freeware 11.0.0.116"

> select &_sqlplus_release from dual;
old 1: select &_sqlplus_release from dual
new 1: select 1803000000 from dual
1803000000
----------
1803000000

You can also just connect to sqlplus through commande line. In LINUX you can do the following:
[orafresh#ljsrv1123 ~]$ sqlplus / as sysdba
Which will return:
SQL*Plus: Release 11.1.0.7.0 - Production on Fri Jul 14 12:47:36 2017
Copyright (c) 1982, 2008, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release
11.1.0.7.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options

Related

Exp error in Unix

Simply put, I get a ` exp error when trying to start a different shell from my putty session.
This is my .bashrc file
export QHOME=/opt/q
export PATH=$PATH:$QHOME
alias q='rlwrap -c q'
The paths are correct, I can't find any information on the error.
[myname#dev-unixtrain ~]$ q
xxx+ 2.7 2011.08.16 Copyright (C) xxxx-xxxx Name Systems
l64/ 1()core 992MB myname dev-unixtrain.company.com 10.29.4.56 2014.03.16 company.com INTERNAL #45486
'exp
So it loads up and automatically goes back to the unix shell.
Any ideas on what the cause might be??
TIA
This is a licence error. You're trying to use q with an expired licence.

Nsclient: How can i display Windows HDD health on Nagios

i want to monitor hard-drive's health of my windows server, for this i have installed Smarttools(smartmontools-6.1-2.win32-setup.exe).
My question is, how can i display commands output on Nagios-Server via nrpe or somewhat else.
Some info: Nagios-Core-3.5, smartmontools-6.1-2,
Commands output on windows machine:
c:> smartctl.exe /dev/sda -l selftest
smartctl 6.1 2013-03-16 r3800 [i686-w64-mingw32-xp-sp2] (sf-6.1-2)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF READ SMART DATA SECTION ===
SMART Self-test log structure revision number 1
Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error
# 1 Short offline Completed without error 00% 17592 -
# 2 Extended offline Completed without error 00% 17393 -
# 3 Short offline Completed without error 00% 17392 -
c:> smartctl.exe /dev/sda -H
smartctl 6.1 2013-03-16 r3800 [i686-w64-mingw32-xp-sp2] (sf-6.1-2)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
C:>smartctl -d ata /dev/sda -i
smartctl 6.1 2013-03-16 r3800 [i686-w64-mingw32-xp-sp2] (sf-6.1-2)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF INFORMATION SECTION ===
Model Family: Seagate Barracuda 7200.9
Device Model: ST3802110A
Serial Number: 5LR7M728
Firmware Version: 3.AAJ
User Capacity: 80,026,361,856 bytes [80.0 GB]
Sector Size: 512 bytes logical/physical
Device is: In smartctl database [for details use: -P show]
ATA Version is: ATA/ATAPI-7 (minor revision not indicated)
Local Time is: Fri Jun 07 19:02:13 2013 IST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled
Any help would greatly appreciated.
You have two issues.
You need to be able to get Nagios to run a check remotely on your Windows server, and
You need to be able to get the data into a Nagios-compatible format.
For the first, you can probably install an agent such as NC_Net or NSClient++. This can be queried using either check_nt or check_nrpe. I would recommend using NC_Net.
For the second, you will likely have to write your own script to run the command and output in Nagios plugin format (one line of text, and an exit status of 0/1/2/3 for OK/Warn/Crit/Unknown). This script can be remotely called via check_nrpe.
However, if your goal is simply to monitor disk space, you can do that using the standard check functions builtin to NC_Net or NSClient++
You may find pre-written scripts at monitoringexchange.org , such as this

sending query to sqlplus

I have a script file which sends query to sqlplus and sends the output to some other output file.
However, this output file contain some info from sqlplus - some kind of greeting.
SQL*Plus: Release 11.2.0.3.0 Production on Tue Jan 15 12:30:40 2013
Copyright (c) 1982 2011 Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning Real Application Clusters Automatic Storage Management OLAP
Data Mining and Real Application Testing options
is there some way to execute the script so that this greeting will not be as part of a file?
You can use the sqlplus -s option when you connect to the database.
Execsqlstatement1="select
'ZZZ|'
||count(*) total
from table1"
$ORACLE_HOME/bin/sqlplus user/tneal01 << Eossql
set lines 80
set pages 50000
set timing on
spool /user/tneal01/SPOOL/output.`date +%Y-%m-%d`.tmp
$Execsqlstatement1
/
spool off
quit;
Eossql
Now if you don't want anything besides the result in the output file you can do something like this in your script:
grep 'ZZZ' $OutPutDir/$OutPutFile.$today.tmp|cut -d"|" -f2- >$OutPutDir/$OutPutFile.$today.txt
Here is a full example on why this works:
#!/bin/ksh
today=`date "+%Y-%m-%d"`
OutPutDir="/users/ttead01/SPOOL"
OutPutFile="output"
#add sql statements here
Execsqlstatement1="select
'ZZZ|'
||count(*) total
from users"
#adding connection details here
$ORACLE_HOME/bin/sqlplus tead01/rangers $SQLPLUS -s / << Eossql
set lines 80
set pages 50000
set timing on
spool /users/ttead01/SPOOL/output.`date +%Y-%m-%d`.tmp
$Execsqlstatement1;
spool off
quit;
Eossql
#check to make sure no ORA errors in the query
grep "ORA-" $OutPutDir/$OutPutFile.$today.tmp
if [ $? -eq 0 ]
then
echo "LOG MESSAGE sql select failed"
exit 1
fi
#Seach for ZZZ and cut out junk and send only result to a .txt file
grep 'ZZZ' $OutPutDir/$OutPutFile.$today.tmp|cut -d"|" -f2- >$OutPutDir/$OutPutFile.$today.txt
#Remove the .tmp file if .txt was created
if [ $? -eq 0 ]
then
/usr/bin/rm -f $OutPutDir/$OutPutFile.$today.tmp
else
exit 1
fi
Now for the test:
bash-3.2$ test.sh
Copyright (c) 1982, 2010, Oracle. All rights reserved.
SQL> set autocommit on;
SQL> rem set linesize 132;
SQL> define _editor = vi
SQL> alter session set nls_date_format = 'YYYYMMDD HH24MISS';
Session altered.
SQL> SQL> SQL> SQL> SQL> 2 3 4 5 6 7 8
TOTAL
--------------------------------------------
ZZZ|32
Elapsed: 00:00:00.17
Now let's look at the output .txt file:
bash-3.2$ cat output.2016-05-28.txt
32
bash-3.2$

SQL Server and Rails trouble

note: this is a repost. This question was previously deleted for undisclosed reasons
Ok, I've been trying to get this to work like all day now and I'm barely any further from when I started.
I'm trying to get Ruby On Rails to connect to SQL Server. I've installed unixODBC and configured it and FreeTDS and installed just about every Ruby gem relating to ODBC that exists.
(This has been updated to show the output of isql with -v)
[earlz#earlzarch myproject]$ tsql -S AVP1 -U sa -P pass
locale is "en_US.UTF-8"
locale charset is "UTF-8"
1> quit
[earlz#earlzarch ~]$ isql -v AVP1 sa pass
[IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified
[ISQL]ERROR: Could not SQLConnect
[earlz#earlzarch myproject]$ rake db:version
(in /home/earlz/myproject)
rake aborted!
IM002 (0) [unixODBC][Driver Manager]Data source name not found, and no default driver specified
(See full trace by running task with --trace)
so, as you can see, tsql works, but not isql. What is the difference in the two that breaks it?
/etc/odbc.ini
[AVP1]
Description = ODBC connection via FreeTDS
Driver = TDS
Servername = my.server
UID = sa
PWD = pass
port = 1232
Database = mydatabase
/etc/odbcinst.ini
[TDS]
Description = v0.6 with protocol v7.0
Driver = /usr/lib/libtdsodbc.so
Setup = /usr/lib/libtdsS.so
CPTimeout =
CPReuse =
FileUsage = 1
(and yes, I've made sure that the .so files exist)
the relevant part in freetds.conf
[AVP1]
host = my.server
port = 1232
tds version = 8.0
and finally, my database.yml
development:
adapter: sqlserver
mode: odbc
dsn: AVP1
username: sa
password: pass
Can anyone please help me before I pull all my hair out?
I am using a 64 bit Arch Linux that is completely up to date.
What could be causing isql to fail. I've tried every solution I've seen so far for this problem but none of them are actually working for me. Do I have to recompile FreeTDS or something?
Ok, I have also verified with strace that it is finding the configuration file, as shown by this excerpt:
open("/etc/odbc.ini", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=159, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc71fe09000
read(3, "[AVP1]\n Description = ODBC "..., 4096) = 159
If anyone has gotten tsql to work but has searched far and wide on the Internet and has troubleshooted their configs and still has not been able to get isql to work check your server logs.
I have been troubleshooting a Xubuntu 12.04 unixodbc install and config for a week now and tried everything possible to get it fixed when I decided to check my windows server event viewer to see what was happening when the request was coming into the server or if a request was even coming into the server and discovered that the problem was that I couldn't get into a specific database. I was able to get into SQL Server ok but not the actual DB I had listed in my odbc.ini file.
Here is the specific text in the event log "Login failed for user 'ePMX'.
Reason: Failed to open the explicitly specified database. [CLIENT:
192.168.27.25]".
What sparked my interest was the word "explicit". So I simply commented out the Database = <DB Name> and suddenly everything worked and I got the SQL prompt after untold hours of researching and trying everything possible.
So if you are having trouble using unixodbc don't forget to troubleshoot the server side of things as well the client side because I have seen tons of posts where people had the exact same problem I was having but there was never any response to how to resolve it so I am guessing that a large number of the people that were having the issue were Server side issues.
For a great troubleshooting tool use osql rather than isql(osql actually in fact uses isql to connect) because it will go through the connection process step by step and give you details about where the failure occurs. It is used the same way you use isql:
osql <DSN> <user> <password>.
So as I said be sure to check your server logs if you have tried everything else and have been unable to figure out what the problem is.
Ok, I finally figured it out after only 2 straight days of banging my head against the wall.
I'll try to give as much info as possible so that if someone finds this in the same situation I was in, they'll find this useful.
[earlz#earlzarch ~]$ cat /etc/odbc.ini
[AVP1]
Description=ODBC connection via FreeTDS
Driver=/usr/lib/libtdsodbc.so
Server=192.168.0.100
UID=sa
PWD=pass
Port=1232
ReadOnly=No
[earlz#earlzarch ~]$ cat /etc/odbcinst.ini
[TDS]
Description = v0.60 with protocol v7.0
Driver = /usr/lib/libtdsodbc.so
Driver64 = /usr/lib
Setup = /usr/lib/libtdsS.so
Setup64 = /usr/lib
CPTimeout =
CPReuse =
FileUsage = 1
[earlz#earlzarch ~]$ cat /etc/freetds/freetds.conf
[global]
tds version = 8.0
initial block size = 512
swap broken dates = no
swap broken money = no
try server login = yes
try domain login = no
cross domain login = no
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
[TDS]
host = 192.168.0.100
port = 1232
tds version = 8.0
and if your lucky, after that:
[earlz#earlzarch ~]$ isql -v AVP1
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[01000][unixODBC][FreeTDS][SQL Server]Adaptive Server connection failed
[ISQL]ERROR: Could not SQLConnect
[earlz#earlzarch ~]$ isql -v AVP1 sa pass
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
I did not have to set any kind of environmental variables and I didn't have to manually compile anything either with Arch Linux 64bit (date April 7th, 2010). After getting isql to work, Rails immediately connected to the database also. Now I just have to figure out why db:schema:load isn't working, but thats another question :)
Also, notice the only real difference between this set of files and the last is in /etc/odbc.ini I set the Driver field to be the actual file name of a driver rather than named for some configuration entry.
When building FreeTDS, current versions of SQL Server need TDS protocol v8 (http://www.freetds.org/userguide/config.htm):
./configure --with-tdsver=8.0 --enable-msdblib

Write current svn version into text file

I have a rails site. I'd like, on mongrel restart, to write the current svn version into public/version.txt, so that i can then put this into a comment in the page header.
The problem is getting the current local version of svn - i'm a little confused.
If, for example, i do svn update on a file which hasn't been updated in a while i get "At revision 4571.". However, if i do svn info, i get
Path: .
URL: http://my.url/trunk
Repository Root: http://my.url/lesson_planner
Repository UUID: #########
Revision: 4570
Node Kind: directory
Schedule: normal
Last Changed Author: max
Last Changed Rev: 4570
Last Changed Date: 2009-11-30 17:14:52 +0000 (Mon, 30 Nov 2009)
Note this says revision 4570, 1 lower than the previous command.
Can anyone set me straight and show me how to simply get the current version number?
thanks, max
Subversion comes with a command for doing exactly this: SVNVERSION.EXE.
usage: svnversion [OPTIONS] [WC_PATH [TRAIL_URL]]
Produce a compact 'version number' for the working copy path
WC_PATH. TRAIL_URL is the trailing portion of the URL used to
determine if WC_PATH itself is switched (detection of switches
within WC_PATH does not rely on TRAIL_URL). The version number
is written to standard output. For example:
$ svnversion . /repos/svn/trunk
4168
The version number will be a single number if the working
copy is single revision, unmodified, not switched and with
an URL that matches the TRAIL_URL argument. If the working
copy is unusual the version number will be more complex:
4123:4168 mixed revision working copy
4168M modified working copy
4123S switched working copy
4123:4168MS mixed revision, modified, switched working copy
If invoked on a directory that is not a working copy, an
exported directory say, the program will output 'exported'.
If invoked without arguments WC_PATH will be the current directory.
Valid options:
-n [--no-newline] : do not output the trailing newline
-c [--committed] : last changed rather than current revisions
-h [--help] : display this help
--version : show version information
I use the following shell script snippet to create a header file svnversion.h which defines a few constant character strings I use in compiled code. You should be able to something very similar:
#!/bin/sh -e
svnversion() {
svnrevision=`LC_ALL=C svn info | awk '/^Revision:/ {print $2}'`
svndate=`LC_ALL=C svn info | awk '/^Last Changed Date:/ {print $4,$5}'`
now=`date`
cat <<EOF > svnversion.h
// Do not edit! This file was autogenerated
// by $0
// on $now
//
// svnrevision and svndate are as reported by svn at that point in time,
// compiledate and compiletime are being filled gcc at compilation
#include <stdlib.h>
static const char* svnrevision = "$svnrevision";
static const char* svndate = "$svndate";
static const char* compiletime = __TIME__;
static const char* compiledate = __DATE__;
EOF
}
test -f svnversion.h || svnversion
This assumes that you would remove the created header file to trigger the build of a fresh one.
If you just want to print latest revision of the repository, you can use something like this:
svn info <repository_url> -rHEAD | grep '^Revision: ' | awk '{print $2}'
You can use capistrano for deployment, it creates REVISION file, which you can copy to public/version.txt
It seems that you are running svn info on the directory, but svn update on a specific file. If you update the directory to revision 4571, svn info should print:
Path: .
URL: http://my.url/trunk
Repository Root: http://my.url/lesson%5Fplanner
Repository UUID: #########
Revision: 4571
[...]
Last Changed Rev: 4571
Note that the "last changed revision" does not necessarily align with the latest revision of the repository.
Thanks to everyone who suggested capistrano and svninfo.
We do actually use capistrano, and it does indeed make this REVISION file, which i guess i saw before but didn't pay attention to. As it happens, though, this isn't quite what i need because it only gets updated on deploy, whereas sometimes we might sneakily update a couple of files then restart, rather than doing a full deploy.
I ended up doing my own file using svninfo, grep and awk as many people have suggested here, and putting it in public. This is created on mongrel start, which is part of the deploy process and the restart process so gets done both times.
thanks all!

Resources