LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-11-2007, 07:06 AM   #1
yusufs
Member
 
Registered: Oct 2007
Posts: 162

Rep: Reputation: 30
script help


Hai all,

am using a script like this to get the no of sessions in the oracle..


like

sqlplus username/password
select count(*) from V$session where status='ACTIVE';

am having the above command in a script ..


I want to store this count(*) in a variable and print it such that when the script is executed, it should print


25 sessions are active now at date and time

Please guide


Yusuf
 
Old 12-12-2007, 05:23 AM   #2
cmnorton
Member
 
Registered: Feb 2005
Distribution: Ubuntu, CentOS
Posts: 585

Rep: Reputation: 35
Embedded SQL

The scripting or programming language you are using needs to support embedded SQL. I'm using Informix 4gl, and while I can write .sql file directives to load, delete, drop, insert, or whatever to tables in my database, I have to write a program either in C, ESQL/C, 4GL, or another language that supports embedded SQL. In that way, I can store variables.

I know of now way a SQL script (.sql) on its own can save a value.
 
Old 12-12-2007, 02:06 PM   #3
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
create a sql script called test.sql:
Code:
set heading off;
select count(*) from V$session where status='ACTIVE';
exit;
Create a shell script that calls this and processes the output:

Code:
#!/bin/bash

echo "$(sqlplus -S '/ as sysdba' @test.sql|grep -v '^$'|sed 's/^\t\t*//g') sessions are active now at $(date)"
You may want to structure the date format, and I am going on the assumption that you are running the script as the oracle account and the default '/ as sysdba' works (as it would normally given the script running as oracle)
 
Old 12-12-2007, 02:10 PM   #4
yusufs
Member
 
Registered: Oct 2007
Posts: 162

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by Disillusionist View Post
create a sql script called test.sql:
Code:
set heading off;
select count(*) from V$session where status='ACTIVE';
exit;
Create a shell script that calls this and processes the output:

Code:
#!/bin/bash

echo "$(sqlplus -S '/ as sysdba' @test.sql|grep -v '^$'|sed 's/^\t\t*//g') sessions are active now at $(date)"
You may want to structure the date format, and I am going on the assumption that you are running the script as the oracle account and the default '/ as sysdba' works (as it would normally given the script running as oracle)
Thanks Disillunioist and Norton.. will check and let you know about this.


Thanks
Yusuf
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute a ssh script on Linux server from Windows through a bat script? wanna13e Programming 13 10-23-2009 02:41 AM
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
Shell Script: want to insert values in database when update script runs ring Programming 2 10-25-2007 10:48 PM
i get an error message running php script inside a cgi script. repolona Linux - Software 0 02-22-2007 09:10 PM
linux 9 and java script error - premature end of script header sibil Linux - Newbie 0 01-06-2004 04:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration