How to check if database exists?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check if database exists?
# 1  
Old 09-09-2008
How to check if database exists?

Hi folks!

First off I'm working with a Sybase DB.

I'm using you're basic ISQL command to connect to my Sybase DB...

isql -S$DB_SERVER -D$DB_NAME -U$DB_USR -P$DB_PWD <<!EOF > $log_file

My question is, is there a way to determine if a database exists using shell script?

For example, if somehow I can check if a database called DB_Test1 exists do the following...

isql -S$DB_SERVER -D$DB_Test1 -U$DB_USR -P$DB_PWD <<!EOF > $log_file

else do the following...

isql -S$DB_SERVER -D$DB_Test2 -U$DB_USR -P$DB_PWD <<!EOF > $log_file

Thanks for any help!
# 2  
Old 09-09-2008
Quote:
Originally Posted by Fatbob
Hi folks!

First off I'm working with a Sybase DB.
...
My question is, is there a way to determine if a database exists using shell script?

Doesn't Sybase have a command to do that? If not, you'll have to discover the location of its files and search there.
# 3  
Old 09-10-2008
Just in case this might help someone else searching this forum one day, here is a good solution someone over at the dbforums provided me.

Code:
isql -S$DB_SERVER -U$DB_USR -P$DB_PWD <<EOF | grep "$DB_NAME"
sp_helpdb
go
EOF
if [ $? -eq 0 ] 
then
  echo 'db found'
  : do some stuff
else
  echo 'db not found'
  : do some other stuff
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Check if file exists

I need to check whether a file exists and has been changed. The file should contain a specific string. The file should also have been changed within the last ten seconds. How do I do that? (3 Replies)
Discussion started by: locoroco
3 Replies

2. Shell Programming and Scripting

To check if file exists

Hi, I have the below code written. However I am not getting the desired output I am checking if the particular path has file in it. #!/bin/bash ls -l /IRS2/IRS2_ODI/INFILE/*LS* 1>/dev/null 2>/dev/null if then echo $? echo "File Exists" fi ... (3 Replies)
Discussion started by: Shanmugapriya D
3 Replies

3. Shell Programming and Scripting

Check if file exists or not

Hi, I want to check if the file exists or not in the directory. i am trying below code but not working. File="/home/va59657/Account_20090213*.dat" echo "$File" if ]; then echo "file found" else echo "file not found" fi However i am getting file not found even if file exits as... (5 Replies)
Discussion started by: Vivekit82
5 Replies

4. UNIX for Dummies Questions & Answers

How to check if a number exists?

Hello, May i please know how do i check if the given input argument is one of the listed numbers then success else failure. I am using bash shell. if then echo "success" else echo "failure" fi Thank you. (2 Replies)
Discussion started by: Ariean
2 Replies

5. Shell Programming and Scripting

Check if PID exists

In a Shell Script what is the most generic way to find in the PID exists or not. If it does not exist how can I echo the user "PID does not exist" & terminate the unix script ? If the command can work on most flavors of operating system the more useful I will find it to be. Current system... (16 Replies)
Discussion started by: mohtashims
16 Replies

6. Shell Programming and Scripting

File exists, but cannot be opened.How to check- whether it could be opened to read when it exists

Hi #Testing for file existence if ; then echo 'SCHOOL data is available for processing' else echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING' : i wrote a script, where it begins by checking if file exists or not. If it exists, it truncates the database... (2 Replies)
Discussion started by: rxg
2 Replies

7. Shell Programming and Scripting

how to check to see if a file exists?

I want to write a script to see if various files exist. What I want to do is have the script search in various directories if a file exist, and if not, then output something like "/path/file does not exist". I don't actually know of how to check and see if a file exists or not. What I have in mind... (2 Replies)
Discussion started by: astropi
2 Replies

8. Shell Programming and Scripting

Check to see if a file exists?

Hi. I'd like to have an IF-Then-Else statement where I can check to see if a file exists? We have the Bourne Shell by default. I'm looking for the syntax to do something like this: if myfile.txt exists then ...my code else ...my code end if Any help would be greatly... (5 Replies)
Discussion started by: buechler66
5 Replies

9. Shell Programming and Scripting

How to check if a direcorty exists?

Hi Good people :D How do I check if a directory exists, if it does then carry on rest of the script, otherwise exit. ------------- cd $mainfolder/system1 #unzips files arrived in last 24 hrs into temp directory find * -mmin -1440 -exec unzip {} \; I'd like to check here if temp... (2 Replies)
Discussion started by: SunnyK
2 Replies

10. Shell Programming and Scripting

check if directory exists

Hi, I need to prompt for a response from a user to enter a path read dest_dir?"Please Enter Directory :" How do I do this until a valid directory is entered by the user. I can use to check the existence of the directory. However when I try the following I cannot get it to work. while ... (2 Replies)
Discussion started by: jerardfjay
2 Replies
Login or Register to Ask a Question