Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8005479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:14:36+00:00 2026-06-04T17:14:36+00:00

I am looking to enclose some Oracle components within a Bash script that will

  • 0

I am looking to enclose some Oracle components within a Bash script that will perform a set of goals:

  1. Log into a remote server (where my Oracle DB resides) as root.
  2. Performs an “su – oracle”.
  3. Logs into sqlplus environment as a specific Oracle user.
  4. Performs an SQL select command and stores the output of that command into a variable.
  5. Displays the result of that variable in the Bash shell.

I have looked through a couple examples here on stackoverflow, many of which seem to go over executing a command but not necessarily detailing how to display the output to the user (although I am still examining a few more). For example, assuming all key exchanges are setup beforehand, a method could be to use the following:

#!/bin/sh
ssh -q root@5.6.7.8
sqlplus ABC/XYZ@core <<ENDOFSQL
select CREATE_DATE from PREPAID_SUBSCRIBER where MSISDN='12345678912';
exit;
ENDOFSQL

Instead, here is how I tried to set this up:

#!/bin/sh
datasource_name=`echo "select CREATE_DATE from PREPAID_SUBSCRIBER where MSISDN='12345678912';" | ssh -q 5.6.7.8 "su - oracle -c 'sqlplus -S ABC/XYZ@core'" | tail -2 | head -1`

Ideally, the datasource_name variable should now either take on values:

no rows selected

Or if there is an entry within the table:

CREATE_DATE
-------------------
07-06-2009 18:04:48

The tail and head commands are to get rid of the empty lines in the output, and the ssh -q and sqlplus -S options are for ignoring warnings.

However, when I run that command, and do an:

echo "${datasource_name}"

I get…

Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell.

…instead of one of the two outputs above. If I understand correctly, this is a warning that can be caused depending on whether a specific shell is used, but most online sources indicate that this can be ignored. The nice thing about this warning is that it appears my command above is actually running and storing “something” into datasource_name, but it just isn’t what I want.

Now to simplify this problem, I noticed I get the same tty warning when I simply try to su to oracle on the remote machine from the box where the bash script runs:

ssh root@5.6.7.8 "su - oracle"
Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell.

If I do the following, I actually get into the sqlplus environment successfully with no issues:

ssh -q root@5.6.7.8 "su - oracle -c 'sqlplus ABC/XYZ@core'"

SQL*Plus: Release 9.2.0.4.0 – Production on Tue May 29 12:35:06 2012

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

Connected to: Oracle Database 10g Enterprise Edition Release
10.2.0.4.0 – 64bit Production With the Partitioning, Real Application Clusters, OLAP, Data Mining and Real Application Testing options

SQL>

If I understand why the problem above is occurring, it is possible that I can figure out how to get my script to work properly. Any suggestions would be greatly appreciated! Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:14:37+00:00Added an answer on June 4, 2026 at 5:14 pm

    change the first line to:

    ssh -t  root@5.6.7.8 "su - oracle"     
    

    to get a tty to see if that would work for you.

    another thing you can do in your script is to redirect stderr to your variable as well if you would like to see that as well in your variable, which does not appear to be the case for you, though I have done so in the past in some cases. There is an example in the comments below.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for an algorithm which someone has access to that will compute the
Looking for a command that will return the single most recent file in a
Looking for a good set of base objects to start a website up in
Looking at adding some data graphing to a new iPhone app in development (ala
Looking for a C++ async HTTP library so I can download some zip files
I'm looking around for a RegEx that can help me parse an nquad file.
Looking for an equivalent container class that matches to C#'s Arraylist collections class. Is
looking into multi file - drag and drop - upload scripts. we were using
I'm trying to set up some like buttons to a project. These buttons live
Maths101 question - does anyone know how to calculate an ellipse (width/height) that will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.