How to pass a date read from database to the shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pass a date read from database to the shell script?
# 1  
Old 09-15-2009
How to pass a date read from database to the shell script?

Hi
i have a database table which i will query in a sqlplus session and it will either come back with a date or null?

Now, what i want to do is based on the date returned i will either abort or continue with the script execution.

I need to know is there a way other than spooling the date into a file and checking that file later on in my shell script ,to decide whether to continue or abort?

Many thanks
# 2  
Old 09-15-2009
Code:
echo "
set pages 0
set feedback off
select sysdate from dual;
exit;
 "  | sqlplus -s user/pwswd/somedb | tr -s '\n' ' ' | sed 's/ //g' | read answer
if [[ -z "$answer" ]] ; then
   echo "answer is null"
else
   echo "date= $answer"
fi

# 3  
Old 09-15-2009
Hi
I just ran the code after connecting to a database but it returns null for sysdate value.

Any ideas....

---------- Post updated at 08:15 AM ---------- Previous update was at 07:59 AM ----------

Hi
I just ran the code after connecting to a database but it returns null for sysdate value.

Any ideas....
# 4  
Old 09-15-2009
Quote:
Originally Posted by vinoo128
...
Any ideas....
Code:
$
$ cat testscr.sh
#!/usr/bin/bash
dt=`sqlplus -s scott/tiger <<EOF
set heading off feed off pages 0
select hiredate from emp where rownum = $1;
exit
EOF`
if [ -z $dt ]; then
  echo "dt is null"
else
  echo "dt = $dt"
fi
$
$ ./testscr.sh 1
dt = 17-DEC-80
$
$ ./testscr.sh 0
dt is null
$
$

tyler_durden
# 5  
Old 09-15-2009
thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass and read an array in ksh shell script function.?

I'm able to read & print an array in varaible called "filelist" I need to pass this array variable to a function called verify() and then read and loop through the passed array inside the function. Unfortunately it does not print the entire array from inside the funstion's loop. #/bin/ksh... (5 Replies)
Discussion started by: mohtashims
5 Replies

2. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

3. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

4. Shell Programming and Scripting

Read input from file and pass it to sub shell

i have a scenario where in i have to monitor jobs which run in different servers, The job details(job name, host server, etc) are present in a dat file. I have written a script a script which reads the details from the dat file and calls a local method where the job monitoring logic is present.... (2 Replies)
Discussion started by: abubucker0
2 Replies

5. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

6. Shell Programming and Scripting

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each certificate and send the mail to the user. The user takes action to add the new certificate to the storage file and user owns the responsibility to update the input text file with the new certificate... (5 Replies)
Discussion started by: casmo
5 Replies

7. Shell Programming and Scripting

How to pass a variable as a parameter to DB2 database from shell script

I need to pass a variable as a parameter from shell script into a DB2 database. var=bhuk_1123_Q_11/22/09 select * from tbl1 where serial_id='$var'; I have tried executing it using db2 -tvf scriptname Somebody please help me out with this. It is throwing an error. Please tell me how... (2 Replies)
Discussion started by: ss3944
2 Replies

8. Shell Programming and Scripting

Read Oracle Username password SID from single file and pass it to shell

Dear All I am trying to write one shell which will be running through Cron which contain one SQL query. But I want to draw/fetch the Username password and Instance name (required to loging to the database) from one single file to run that SQL query . Also this file contain details of multiple... (2 Replies)
Discussion started by: jhon
2 Replies

9. Shell Programming and Scripting

getting date from shell and pass it to java

Hi, I have a variable called asOfDate in shell script. I need to pass it as a command line argument to a java command which will be called from the same shell script. The format of that variable is "MM/DD/YYYY" while doing echo, it is printing correctly in the java command. ie.... (0 Replies)
Discussion started by: vanathi
0 Replies

10. Shell Programming and Scripting

read a file as input and pass each line to another script

Hi, I am trying to write a ftp script which will read a file for filenames and ftp those files to another server. Here's my ftp script, but it's scanning the current directory for file names. My question is how can I pass multiple files (these files will have the name of data files that need to... (0 Replies)
Discussion started by: sajjad02
0 Replies
Login or Register to Ask a Question