Drop a database from a script
Posted in 2006
A user wanted to drop a database non-interactively from a shell script and his dbaccess here-document wasn't working. Replies pointed out two mistakes: the SQL must read "drop database $DATABASE;" (the keyword "database" was missing), and dbaccess needs dash arguments for no database and stdin input, e.g. `dbaccess - - << EOF` or `echo "drop database ${DATABASE};" | dbaccess - -`. Use double quotes so the shell expands the variable, and `-e` to echo the statements. The drop can still fail if another user has the database open. The poster confirmed it worked.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Topics: Server Administration
I am trying to drop a database from a script e.g.
echo "Drop Database..." $DATABASE
dbaccess << EOF
drop $DATABASE
EOF
This should be simple, unfortunately, I don't have the background in scripting
or running dbaccess as a bg. The version information is IBM Informix Dynamic
Server Version 9.40.UC6.
Can someone either point me at the text or lend a helping hand.
Regards
John
Syntax should be:
dbaccess - << EOF
drop database ....
EOF
Not depending on the version. Could of course fail in case the database is
opened by another user at the same time.
Marcus
-----Original Message-----
From: ids-bounces@iiug.org [mailto:ids-bounces@iiug.org] On Behalf Of JOHN
FLORY
Sent: Tuesday, September 26, 2006 10:04 AM
To: ids@iiug.org
Subject: Drop a database from a script [7537]
I am trying to drop a database from a script e.g.
echo "Drop Database..." $DATABASE
dbaccess << EOF
drop $DATABASE
EOF
This should be simple, unfortunately, I don't have the background in
scripting or running dbaccess as a bg. The version information is IBM
Informix Dynamic Server Version 9.40.UC6.
Can someone either point me at the text or lend a helping hand.
Regards
John
****************************************************************************
***
Forum Note: Use "Reply" to post a response in the discussion forum.
Marcus
Thankyou
I'll try that. The error wasn't opened by another user.
cheers
John
-----Original Message-----
From: Marcus Haarmann [mailto:marcus.haarmann@midoco.de]
Sent: Tuesday, September 26, 2006 5:38 PM
To: Flory, John
Subject: RE: Drop a database from a script [7538]
Syntax should be:
dbaccess - << EOF
drop database ....
EOF
Not depending on the version. Could of course fail in case the database
is
opened by another user at the same time.
Marcus
-----Original Message-----
From: ids-bounces@iiug.org [mailto:ids-bounces@iiug.org] On Behalf Of
JOHN
FLORY
Sent: Tuesday, September 26, 2006 10:04 AM
To: ids@iiug.org
Subject: Drop a database from a script [7537]
I am trying to drop a database from a script e.g.
echo "Drop Database..." $DATABASE
dbaccess << EOF
drop $DATABASE
EOF
This should be simple, unfortunately, I don't have the background in
scripting or running dbaccess as a bg. The version information is IBM
Informix Dynamic Server Version 9.40.UC6.
Can someone either point me at the text or lend a helping hand.
Regards
John
************************************************************************
****
***
Forum Note: Use "Reply" to post a response in the discussion forum.
************************************************************************
*******
Forum Note: Use "Reply" to post a response in the discussion forum.
Thank you to everyone. I have a solution and I am very happy. :-)
Hi,
echo "drop database <database name>;" | dbaccess - -
or
dbaccess - - << EOF
drop database <database name>;
EOF
Both should work. You have to supply the database name for
the <database name> (i.e. without the '<' '>' characters).
If you have the database name set as value of the environment variable
$DATABASE, then:
echo "drop database $DATABASE ;" | dbaccess - -
or more correctly:
echo "drop database ${DATABASE};" | dbaccess - -
Here the double quotes (") are important as they tell the shell to
replace the $DATABASE with the value. When using single quotes (')
instead, then the shell does not do this replacement ...
The two dashes (separated by space) after the dbaccess command
mean that you don't have a server name and no sql script, but you
want to use the command line interface instead of the interactive 4GL
"GUI" interface.
Regards,
Martin
--
Martin Fuerderer
IBM Informix Development Munich, Germany
Information Management
Informix URLs list: http://home.arcor.de/mfu1/informix/urls.html
Informix in the news:
http://www.crn.com/sections/software/software.jhtml?articleId=193004835
IBM Information On Demand Global Conference
October 15-20, 2006, Anaheim, California
see http://www.ibm.com/events/informationondemand
ids-bounces@iiug.org wrote on 26.09.2006 10:03:37:
>
> I am trying to drop a database from a script e.g.
> echo "Drop Database..." $DATABASE
>
> dbaccess << EOF
> drop $DATABASE
> EOF
>
> This should be simple, unfortunately, I don't have the background in
scripting
> or running dbaccess as a bg. The version information is IBM Informix
Dynamic
> Server Version 9.40.UC6.
>
> Can someone either point me at the text or lend a helping hand.
>
> Regards
> John
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
You have a sintax error. The correct script is:
dbaccess << EOF
drop database $DATABASE
EOF
-----Mensaje original-----
De: JOHN FLORY [mailto:john.flory@hp.com]
Enviado el: Martes, 26 de Septiembre de 2006 03:04 a.m.
Para: ids@iiug.org
Asunto: Drop a database from a script [7537]
I am trying to drop a database from a script e.g.
echo "Drop Database..." $DATABASE
dbaccess << EOF
drop $DATABASE
EOF
This should be simple, unfortunately, I don't have the background in
scripting
or running dbaccess as a bg. The version information is IBM Informix Dynamic
Server Version 9.40.UC6.
Can someone either point me at the text or lend a helping hand.
Regards
John
****************************************************************************
***
Forum Note: Use "Reply" to post a response in the discussion forum.
Just for slight modification for those that would want to know what database
was dropped (the output of the script), you might want to use the following:
dbacccess -e - - The -e flag echoes the SQL command processed, following
by its result.
Take care.
Clifton
-----Original Message-----
From: ids-bounces@iiug.org [mailto:ids-bounces@iiug.org] On Behalf Of Martin
Fuerderer
Sent: Tuesday, September 26, 2006 6:48 AM
To: ids@iiug.org
Subject: Re: Drop a database from a script [7543]
Hi,
echo "drop database <database name>;" | dbaccess - -
or
dbaccess - - << EOF
drop database <database name>;
EOF
Both should work. You have to supply the database name for
the <database name> (i.e. without the '<' '>' characters).
If you have the database name set as value of the environment variable
$DATABASE, then:
echo "drop database $DATABASE ;" | dbaccess - -
or more correctly:
echo "drop database ${DATABASE};" | dbaccess - -
Here the double quotes (") are important as they tell the shell to
replace the $DATABASE with the value. When using single quotes (')
instead, then the shell does not do this replacement ...
The two dashes (separated by space) after the dbaccess command
mean that you don't have a server name and no sql script, but you
want to use the command line interface instead of the interactive 4GL
"GUI" interface.
Regards,
Martin
--
Martin Fuerderer
IBM Informix Development Munich, Germany
Information Management
Informix URLs list: http://home.arcor.de/mfu1/informix/urls.html
Informix in the news:
http://www.crn.com/sections/software/software.jhtml?articleId=193004835
IBM Information On Demand Global Conference
October 15-20, 2006, Anaheim, California
see http://www.ibm.com/events/informationondemand
ids-bounces@iiug.org wrote on 26.09.2006 10:03:37:
>
> I am trying to drop a database from a script e.g.
> echo "Drop Database..." $DATABASE
>
> dbaccess << EOF
> drop $DATABASE
> EOF
>
> This should be simple, unfortunately, I don't have the background in
scripting
> or running dbaccess as a bg. The version information is IBM Informix
Dynamic
> Server Version 9.40.UC6.
>
> Can someone either point me at the text or lend a helping hand.
>
> Regards
> John
>
>
>
****************************************************************************
***
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
****************************************************************************
***
Forum Note: Use "Reply" to post a response in the discussion forum.
Thank you..
I'll store this in my hits and trick bag.
Regards
John S Flory
148 Frome Street, Adelaide, SA 5001
+61 8 8408 4233 Phone
+61 417 814 579 Mobile
+61 8 8408 4191 Fax
john.flory@hp.com
This email isintended only for the use of the individual or entity named
above and may contain information that is confidential or privileged. If
you are not the intended recipient, you are hereby notified that any
dissemination, distribution or copyright of this email is strictly
prohibited. If you have received this email in error, please notify HP
immediately by return email and destroy the original message.
-----Original Message-----
From: Julio Gerardo Flores Olvera [mailto:julio.flores@isosa.com.mx]
Sent: Tuesday, September 26, 2006 11:32 PM
To: Flory, John
Subject: RE: Drop a database from a script [7545]
You have a sintax error. The correct script is:
dbaccess << EOF
drop database $DATABASE
EOF
-----Mensaje original-----
De: JOHN FLORY [mailto:john.flory@hp.com]
Enviado el: Martes, 26 de Septiembre de 2006 03:04 a.m.
Para: ids@iiug.org
Asunto: Drop a database from a script [7537]
I am trying to drop a database from a script e.g.
echo "Drop Database..." $DATABASE
dbaccess << EOF
drop $DATABASE
EOF
This should be simple, unfortunately, I don't have the background in
scripting
or running dbaccess as a bg. The version information is IBM Informix
Dynamic
Server Version 9.40.UC6.
Can someone either point me at the text or lend a helping hand.
Regards
John
************************************************************************
****
***
Forum Note: Use "Reply" to post a response in the discussion forum.
************************************************************************
*******
Forum Note: Use "Reply" to post a response in the discussion forum.
Thank you for the great explanation.
Regards
John S Flory
148 Frome Street, Adelaide, SA 5001
+61 8 8408 4233 Phone
+61 417 814 579 Mobile
+61 8 8408 4191 Fax
john.flory@hp.com
This email isintended only for the use of the individual or entity named
above and may contain information that is confidential or privileged. If
you are not the intended recipient, you are hereby notified that any
dissemination, distribution or copyright of this email is strictly
prohibited. If you have received this email in error, please notify HP
immediately by return email and destroy the original message.
-----Original Message-----
From: Martin Fuerderer [mailto:MARTINFU@de.ibm.com]
Sent: Tuesday, September 26, 2006 9:18 PM
To: Flory, John
Subject: Re: Drop a database from a script [7543]
Hi,
echo "drop database <database name>;" | dbaccess - -
or
dbaccess - - << EOF
drop database <database name>;
EOF
Both should work. You have to supply the database name for
the <database name> (i.e. without the '<' '>' characters).
If you have the database name set as value of the environment variable
$DATABASE, then:
echo "drop database $DATABASE ;" | dbaccess - -
or more correctly:
echo "drop database ${DATABASE};" | dbaccess - -
Here the double quotes (") are important as they tell the shell to
replace the $DATABASE with the value. When using single quotes (')
instead, then the shell does not do this replacement ...
The two dashes (separated by space) after the dbaccess command
mean that you don't have a server name and no sql script, but you
want to use the command line interface instead of the interactive 4GL
"GUI" interface.
Regards,
Martin
--
Martin Fuerderer
IBM Informix Development Munich, Germany
Information Management
Informix URLs list: http://home.arcor.de/mfu1/informix/urls.html
Informix in the news:
http://www.crn.com/sections/software/software.jhtml?articleId=193004835
IBM Information On Demand Global Conference
October 15-20, 2006, Anaheim, California
see http://www.ibm.com/events/informationondemand
ids-bounces@iiug.org wrote on 26.09.2006 10:03:37:
>
> I am trying to drop a database from a script e.g.
> echo "Drop Database..." $DATABASE
>
> dbaccess << EOF
> drop $DATABASE
> EOF
>
> This should be simple, unfortunately, I don't have the background in
scripting
> or running dbaccess as a bg. The version information is IBM Informix
Dynamic
> Server Version 9.40.UC6.
>
> Can someone either point me at the text or lend a helping hand.
>
> Regards
> John
>
>
>
************************************************************************
*******
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
************************************************************************
*******
Forum Note: Use "Reply" to post a response in the discussion forum.