title: How to write a shell script to output the result of a query to a text file
body: <p>I want to write a shell script that will have a SQL select query and will output a text file.</p>
  
  <p>My server is Linux, database is oracle.</p>
  
  <p>I connect to my database by: </p>
  
  <pre><code>putty- su - oracle
  . .profile_1120_rdbms
  sqlplus SYSTEM/SYADM
  sql&gt; here i write sql query
  </code></pre>
  
  <p>But i want my query to run from shell script, which run as root user.</p>
  
  <p>I do not know which environments to set /do i need any drivers installed.</p>
  
  <p>I have tried some pieces of code, but they give me <code>sqlplus not found /invalid command</code>. I am not able to connect to db. </p>
  
  <p>Please suggest me if there is some other way... I just want to run my sql from some script and have output in some text file.</p>