473,320 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

checking if the Database exists (by running a batch file)

Hi,
Im v.new to postgres. I needed some help writing batch files.
I wanted to run psql commands in a batch file.
I give 2 inputs to the batch file -- Username and Database name
I want my batch file to do the following things.

- check if a database created by that user exists if true return 1 else return 0

Anyone who knows how to do this , please help !
Jul 2 '08 #1
1 6457
rski
700 Expert 512MB
I'm not sure if you work under linux or windows. This is linux script that meets you requirements
Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/bin/bash
  3. psql -t -c "select * from pg_user u,pg_database d where u.usesysid=d.datdba and usename='$1' and datname='$2'" > myfile
  4. z=`wc -l myfile | cut -d" " -f 1`;
  5. if [ $z -le 1 ]
  6. then echo "0";
  7. else
  8.         echo "1";
  9. fi
  10. rm myfile
  11.  
i guess it is not perfect but i didn;t write a scipt for a long time :).
Jul 2 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: brad | last post by:
I am new to perl and would like to know how to check the return values of a perl program in a batch file. how can I save the return value of the perl program and use it to make decisions as to...
3
by: konsu | last post by:
hello, i would like to write a batch file with all sql commands necessary to create a database, its tables, and populate them with initial data. would the experts please help me with these...
4
by: Bill | last post by:
I need help closing a CMD window when it is executed from Access. 1) The batch file is called from Access. 2) Access closes, 3) the batch runs a copy of the access database (creating a backup)...
2
by: amy | last post by:
the following is my WebMethod (GetPrc) to launch a batch file which will take about 10 seconds to be processed. I get the "The page cannot be displayed...HTTP 500 - Internal server error" for...
1
by: Bucky Pollard | last post by:
I have a web service that needs to create a batch file and call it (since there are no APIs for the functionality I am looking for). I am using the Process and ProcessStartInfo objects. When I try...
2
by: Antonio | last post by:
I recently installed on my Windows 2003 Server the Support tools in order to create DNS using dnscmd.exe. I created a batch file called File.bat which I wanted to run from a webservice but it...
4
by: CliffKing | last post by:
I am trying to use Windows Task Scheduler to run a batch file for an already open MS Access database. Below is the syntax to the batch file: Batch file: DailySalesExport.bat REM This runs the...
1
by: steve | last post by:
Hi all, Here's some work in progress that should allow you to run a batch file as a custom action in a VS deployment project. Yup I know you can use js or wsh, but the target may not have...
14
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In my windows applicationm, i need to excute a batch file. this batch file throws some text and questions to the screen, i need to catch the standard Output, check if it's a question, in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.