Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

db2 script

56 views
Skip to first unread message

J. Terrazas

unread,
Jun 3, 2002, 2:46:45 PM6/3/02
to
Hi All,

When a new script is created through the DB2 Script Centre, we get the
choice of a 'OS command' or 'db2 command'. Are there any examples of a
valid os command or of a valid db2 command? I have searched in the
documentation and I don't see any examples of what these scripts should
look like.

In particular, I'm interested in creating a .cmd file that stops a Win 2000
service, does a db backup and then it restarts the service. I'd like to
schedule the execution of this script through the db2 script centre. Any
ideas, suggestions or examples?

Thanks,

J Terrazas

Larry Menard

unread,
Jun 3, 2002, 4:42:45 PM6/3/02
to
J.,

"OS Commands" are any non-GUI command/program/script that you would/can
run from a command line.

"DB2 Commands" are things you'll find in the DB2 SQL Reference or DB2
Command Reference.

--
Larry Menard
IBM Workstation Database (DB2) Performance Team
Defender of Geese and of All Things Natural
"J. Terrazas" <jter...@symcor.com> wrote in message
news:Xns92229658...@207.35.177.134...

Dmitry

unread,
Jun 4, 2002, 6:15:50 AM6/4/02
to
Hi,

> In particular, I'm interested in creating a .cmd file that stops a Win
2000
> service, does a db backup and then it restarts the service. I'd like to
> schedule the execution of this script through the db2 script centre. Any
> ideas, suggestions or examples?

To create a offline backup you have to disconnect all users, not to stop the
service. The backup utility performs a connection to the database in
exclusive mode.

For example, a .cmd file with db2 commands:

db2 attach to db2inst user db2admin using db2admin
db2 force application all
db2 backup db dbname user db2admin using db2admin to drive

Best regards, Dmitry
--

http://www.ispirer.com/products - Database migration software for IBM DB2,
Oracle, MS SQL Server and MySQL.

"J. Terrazas" <jter...@symcor.com> wrote in message
news:Xns92229658...@207.35.177.134...

J. Terrazas

unread,
Jun 4, 2002, 9:47:32 AM6/4/02
to
"Larry Menard" <lme...@ca.ibm.com> wrote in
news:adgkd9$uag$1...@tornews.torolab.ibm.com:

Larry,

I was experimenting with OS commands in my script but nothing was
working. However, after renaming the script with an extension .cmd, it
works OK. It seems that the script name needed the .cmd extension to
execute. I haven't tried the .bat extension but I suspect that works too.

Thanks,

J Terrazas

J. Terrazas

unread,
Jun 4, 2002, 9:55:10 AM6/4/02
to
"Dmitry" <sup...@ispirer.com> wrote in
news:adi404$10obqc$1...@ID-75577.news.dfncis.de:

Dmitry,

I believe I need to stop the Win 2000 service since it has a connection
to the database I intend to backup. I know forcing all users off works,
but Would my service reconnect to the database automatically after the db
is backed up?

Thanks,

J Terrazas

Larry Menard

unread,
Jun 4, 2002, 10:17:25 AM6/4/02
to
J.,

You don't need the extensions.

OS commands need to be prefixed with an exclamation mark. For example,
consider the following CLP (command line processor script):

connect to mydb
update command options using r on select.out
select * from mytable
!dir select.out
connect reset
terminate

If those 6 lines were in a CLP script called "commands.clp", it would be
run from the shell using the command "db2 -f commands.clp". Do "db2 ?
options" for other CLP options.


--
Larry Menard
IBM Workstation Database (DB2) Performance Team
Defender of Geese and of All Things Natural
"J. Terrazas" <jter...@symcor.com> wrote in message

news:Xns9223639B7...@206.172.150.14...

J. Terrazas

unread,
Jun 4, 2002, 1:22:51 PM6/4/02
to
"Larry Menard" <lme...@ca.ibm.com> wrote in
news:adii65$2iju$1...@tornews.torolab.ibm.com:

Larry,

Yes, you are right. Prefixing the os command with "!" executes the os
command in a db2 script. But, in the Script centre you get 2 choices for
the script type: OS command or DB2 command. If one chooses "OS command",
is the "!" still required before each OS command in the script? If this
is true, then what is the point of offering 2 choices for the script
type? I have experimented with OS command scripts which don't use the
"!" character and if they don't have extension .cmd, then they are not
executed. This is very confusing to me and the db2 documentation doesn't
even pretend to explain a little bit about this very useful feature.

Thanks,

J Terrazas

Larry Menard

unread,
Jun 4, 2002, 3:10:46 PM6/4/02
to
J.,

I'm not familiar with the script center, but I may have misunderstood
you, and I think I see now what you're asking.

If the 2 options ("DB2 Command" and "OS Command") are options that are
applied to the "Script Type", then perhaps you do need the extension. My
misunderstanding was that I thought these 2 options were separately applied
to each line of the script you are building (which I thought would always be
a CLP script).

I'd guess that:

1) If you make the script type "DB2 Command", then you do not need the
extension but you will need to use the "!" prefix for OS commands you put in
the script.

2) If you make the script type "OS Command", then you will not need the "!"
prefix for OS commands, but you will need to:

A) If you're on Windows, name the script with the ".bat" or ".cmd"
extension (those are the only valid script extensions on Windows).
B) Prefix each DB2 commands in the script with "db2 ...".

That seems to make sense to me. Sorry for misunderstanding... I tend to
read things pretty quickly these days... ;-)


--
Larry Menard
IBM Workstation Database (DB2) Performance Team
Defender of Geese and of All Things Natural
"J. Terrazas" <jter...@symcor.com> wrote in message

news:Xns9223881CC...@206.172.150.14...

0 new messages