Operating System - HP-UX
1847009 Members
4676 Online
110258 Solutions
New Discussion

Simple shell script question

 
Craig A. Sharp
Super Advisor

Simple shell script question

I think I am in brain lock :-)

I have a simple shell script:

db2 << EOF
CONNECT TO ISDEV
BACKUP DATABASE ISDEV TO /dev/rmt/2mnb WITH 2 BUFFERS BUFFER 1024
c
EOF

Here is what is supposed to happen

1. Issue the CONNECT TO ISDEV to the db2 command. This works fine.
2. Issue the BACKUP DATABASE ISDEV TO /dev/rmt/2mnb WITH 2 BUFFERS BUFFER 1024
to the db2 command. This works fine.

At this point, the db2 command returns the statement Press (c) to continue or (q) to quit.

I am trying to pass the c to the db2 command in order to answer the question but it is not working.

Any ideas?

Thanks,

Craig
6 REPLIES 6
Hai Nguyen_1
Honored Contributor

Re: Simple shell script question

Craig,

Try this one:

db2 << EOF
CONNECT TO ISDEV
BACKUP DATABASE ISDEV TO /dev/rmt/2mnb WITH 2 BUFFERS BUFFER 1024

c
EOF

Note that I added a blank line right before the "c" line.

Hai
John Palmer
Honored Contributor

Re: Simple shell script question

Looks as though db2 is reading the reply from /dev/tty (your terminal connection) rather than from standard input.

Is there any way to stop it asking for confirmation?

If not, then you could use 'expect' to program this.

Regards,
John
Craig A. Sharp
Super Advisor

Re: Simple shell script question

Thanks for the replies. The extra space did not work. I have also checked to see if we can disable the confirmation but no luck.

I have never used expect but the might be an idea to try.
john korterman
Honored Contributor

Re: Simple shell script question

Hi Craig,
have you tried piping the "c" character to your script, e.g.:
# echo "c" | `your_script`

The quoutes round your_script are back_quotes - try making a separate script with a content like above, although I admit it looks ugly.

regards,
John K.
it would be nice if you always got a second chance
Dietmar Konermann
Honored Contributor

Re: Simple shell script question

John's assumption that db2 reads directly from its controlling terminal may be right...

Probably you could tweak it using the attached small wrapper to detach your script from the terminal? Sometime application give up when there's no terminal. :)

Compile it, e.g. as setsid:

# cc -o setsid setsid.c

Then run your shell script from it.

# ./setsid yourscript.sh

Best regards... Dietmar
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Francisco J. Soler
Honored Contributor

Re: Simple shell script question

Hi, Craig, could you issue a ^M affer the c like this.

.....
WITH 2 BUFFERS BUFFER 1024
c^M
EOF

remember: if you edit the file with vi, to put a ^M you must do it with a ^V^M

Frank.
Linux?. Yes, of course.