Running oracle commands Directly from Command Line

 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications Running oracle commands Directly from Command Line
# 1  
Old 05-11-2010
Running oracle commands Directly from Command Line

In mysql, I can get what I want from a database without having to log into mysql. works great for me and it is perfect.

now, i want to be able to do the same in oracle but I dont know how to.

For example, if i want to retrieve information from the mysql database from the command line, i issue a command similar to the below:

Code:
mysql --pager=/usr/bin/less -u cacti_user -p -e 'select hostname,description,availability,notes,availability_method from host' cacti

Oracle has to have similar thing to this. What is it? How can I retrieve this same information from a database using the command line?
# 2  
Old 05-11-2010
Something like this:
Code:
sqlplus -S user/password@sid << EOF
select sysdate from dual;
EOF

# 3  
Old 05-11-2010
Quote:
Originally Posted by pludi
Something like this:
Code:
sqlplus -S user/password@sid << EOF
select sysdate from dual;
EOF



What is the "sid" part? and is there a way to make a one liner out of that code?
# 4  
Old 05-11-2010
The SID is the system identifier for a database, describing the listener to use to connect. And I wouldn't know of a way to do this in a one-liner.
# 5  
Old 05-11-2010
Code:
$ printf 'select * from dual;' | sqlplus -S '/ as sysdba'

D
-
X

For Oracle >= 10g you don't need to quote the / as sysdba part (or you can use a regular username/password[@service] pair).

Some shells support here-strings via the <<< operator:

Code:
$ sqlplus -S '/ as sysdba'<<<'select * from dual;'

D
-
X

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Another one line command where I'd like to determine if Ubuntu or Red Hat when running command

Hello Forum, I'm making very good progress on my report thanks to the very helpful people on this forum. I've been able to successfully create my report for my Red Hat servers. But I do have a few ubuntu servers in the mix and I'd like to capture some data from them when an ssh connection is... (8 Replies)
Discussion started by: greavette
8 Replies

2. Shell Programming and Scripting

Issue with running multiple commands withing su command

RHEL 6.2/Bash shell root user will be executing the below script. It switches to oracle user and expect to do the following things A. Source the environment variables for BATGPRD Database (the file used for sourcing is shown below after the script) B. Shutdown the DB from sqlplus -- The... (13 Replies)
Discussion started by: omega3
13 Replies

3. Shell Programming and Scripting

Redirect output directly with DOS end of line

Hi guys, I have some echo scripts and awk scripts like these: echo "some text" > output1 . . awk '{....}{print}' input > output2Both output1 and output2 are saved with unix END Of Line, then, is there an option to include within echo command and awk command to save the output as DOS END Of... (3 Replies)
Discussion started by: Ophiuchus
3 Replies

4. UNIX for Dummies Questions & Answers

Running set options from the command line and bash command

I'm reading about debugging aids in bash and have come across the set command. It says in my little book that an addition to typing set you can also use them "on the command line when running a script..." and it lists this in a small table: set -o option Command Line... (5 Replies)
Discussion started by: Straitsfan
5 Replies

5. UNIX for Dummies Questions & Answers

How do you use UNIX commands in the Windows Command Line?

I tried opening the windows command line and typing UNIX commands, but they don't work. It kept saying that it was not recognized as an internal or external command, operable program or batch file. Removed strange sentence with even stranger link I need to use UNIX commands such as 'less',... (9 Replies)
Discussion started by: vlay2
9 Replies

6. Solaris

what is the command to see which database ie..oracle in running on solaris 10

what is the command to see which database ie..oracle in running on solaris 10 (2 Replies)
Discussion started by: tv.praveenkumar
2 Replies

7. UNIX for Dummies Questions & Answers

Running two commands in one line

hi! how do i run 2 command from the same line e.g: 'which screen' and then ls -la 'which screen' (4 Replies)
Discussion started by: rdns
4 Replies

8. HP-UX

command su : enter directly

Hi, a simple question : How can I sent user and password to the command su. I need this for a script, but the problem is the command su wait for the password. Thanks. (2 Replies)
Discussion started by: mvaquerm
2 Replies

9. Shell Programming and Scripting

Script an Oracle Command Line Blackout

Has anyone scripted an OEM (Oracle Enterprise Manager) blackout within a shell script? I can script the "emctl blackout" command, however, there are issues with unique names, etc. in 10g and I hate to re-create the wheel if someone has found a great way to do this. Thanks for your time. (0 Replies)
Discussion started by: pattieatte
0 Replies

10. Shell Programming and Scripting

Commands and Command Line Flags

Hello I'm very new to unix, am learning it as part of my new job. I have a book which has a list in the back, of a number of commands and their command line flags, detailing what these flags are used for. I've been looking everywhere for an electronic copy of this type of list, so I can... (4 Replies)
Discussion started by: Kedgeboy
4 Replies
Login or Register to Ask a Question