Question: line continuation in shell script

deany

ADSM.ORG Member
Joined
Apr 18, 2007
Messages
23
Reaction score
0
Points
0
Colleagues,

I am trying to embed dsmadmc commands in a korn shell running on AIX.
The example below is an illustration of what I am attempting to acheive.
Future scripts using the select command warrent the use of a line continuation capability for readability purposes.



filename = t1.ksh
-----------------------------------------------------------------------
#!/bin/ksh
#
#set -x
#
pw=cat `/usr/local/bin/tsm/.passwd`
/usr/bin/dsmadmc -id=admin -password=$pw query volume=A00002L3 -
format=detailed

-----------------------------------------------------------------------

When executing this simple script (./t1.ksh) the (-) line continuation causes the script to abend.

When executing this script without the (-), the script runs successfully however the second line (format=detailed) is ignored.

A suggestion made in an existing question within this forum said to subtitute a new line in place of the (-) character. This did not work either.

Can you shed some light on how to use line continuation for tsm commands within a korn shell?

If the use of korn shell programs is not the recommended way to handle scripting tsm commands, please suggest alternate solutions.

Thank-you ..... DeanY
 
Try some quotes. I don't have access at the moment to test this but ...

/usr/bin/dsmadmc -id=admin -password=$pw 'query volume=A00002L3 -
format=detailed'
 
BBB,

Thank-you for your suggestion. When I try your suggestion of using quotes around the existing command, the script abends with an error code ANR2023E - Extraneous parameter -A00002L3.

When I remove the (-) continuation character from the quote enclosed command it works. The second line which includes (format=detailed) is processed.

When transferring this technique to a more complex statement using the select statement problems re-occur.

For example: (I stole this code from user = tsmtodd). The original question was posed by tsmtodd and was titled "Select to total backup bytes by node per day". Found at: http://adsm.org/forum/showthread.php?t=9608. Within the tsm admin console the select statement works. tsmtodd's command starts with the select statement below.

my filename: total.ksh
-----------------------------------------------------------------------

#!/bin/ksh
#
set -x
#
pw=`cat /usr/local/bin/tsm/.passwd`

/usr/bin/dsmadmc -id=admin -password=$pw 'select ENTITY AS "Node",
cast(start_time as date) as "Date",
CAST(SUM(BYTES/1048576)
AS DECIMAL(9,2)) AS "MB"
FROM SUMMARY
WHERE ACTIVITY IN ('BACKUP','ARCHIVE')
GROUP BY ENTITY, start_time
ORDER BY "Node"

-----------------------------------------------------------------------

To execute: ./total.ksh
-----------------------------------------------------------------------
Output is:

(Paraphrasing - header information about establishing a session with the server. Server version 5.3.2.0, date and time info.)

ANS8000I Server command: 'select ENTITY AS "Node" , cast(start_time as date) as "Date" , CAST(SUM(BYTES/1048576) AS DECIMAL(9,2)) AS "MB" FROM SUMMARY WHERE ACTIVITY IN (BACKUP,ARCHIVE) GROUP BY ENTITY, start_time ORDER BY "Node"'

ANR2916E The SQL data types VARCHAR(64) and ENUMERATED(Unresolved) are incompatible for operator 'IN'.

|
........................................v.....................................................
"FROM SUMMARY WHERE ACTIVITY IN (BACKUP,ARCHIVE) GROUP BY ENTI

ANS8001I Return code 3.
ANS8002I Highest return code was 3.
----------------------------------------------------------------------

Can you shed some additional light on this? I believe it is another theme and variation of the line continuation problem not being handled properly.

Thanks-you ...... DeanY
 
I believe the UNIX OS will only interpret the \ as a continuation character unless you put the TSM command into a macro and have it call the macro. In that case I believe the \ is the continuation character. I checked the docs and it said the - will work also, but try the \ in the command and see if that will work.
 
I haven't tried it yet, but dashes, parentheses, etc mean something to Korn shell. If you want to try to pass that to your dsmadmc, you might try to prefix punctuation with a backslash ( \ ).
Code:
/usr/bin/dsmadmc -id=admin -password=$pw 'query volume=A00002L3 \- 
format=detailed'

or

Code:
/usr/bin/dsmadmc -id=admin -password=$pw 'select ENTITY AS \"Node\"\,
cast\(start_time as date\) as \"Date\"\,
CAST\(SUM\(BYTES\/1048576\)
AS DECIMAL\(9\,2\)\) AS "MB"
FROM SUMMARY
WHERE ACTIVITY IN \(\'BACKUP\'\,\'ARCHIVE\'\)
GROUP BY ENTITY\, start_time
ORDER BY \"Node\"

But Chad's right. For complex stuff, use a macro and call it good. Or perhaps write a script and pass it values as needed.
 
BBB, Chad and tsmtodd,

Thank you for your time and support. I would have to agree with you on your recommendation to use macros on complex tsm commands within korn shell scripts.

In smaller scripts as I have illustrated below, the IBM manual "Tivoli Distributed Monitoring" Chapter 3 page 51 as an interesting recommendation.

If you use double quotes around the entire statement you can acheive a positive result.

- first (") is before the first select
- second and final (") is after the "Node" word.

So:


my filename: total.ksh
-----------------------------------------------------------------------

#!/bin/ksh
#
set -x
#
pw=`cat /usr/local/bin/tsm/.passwd`

/usr/bin/dsmadmc -id=admin -password=$pw "select ENTITY AS "Node",
cast(start_time as date) as "Date",
CAST(SUM(BYTES/1048576)
AS DECIMAL(9,2)) AS "MB"
FROM SUMMARY
WHERE ACTIVITY IN ('BACKUP','ARCHIVE')
GROUP BY ENTITY, start_time
ORDER BY "Node""

-----------------------------------------------------------------------

To execute: ./total.ksh

The korn shell script executes successfully. Again this works for simple/single sql statements that you may want use as canned commands; and not have to type all this code.

Thanks again ...... DeanY
 
Not sure that I agree with the macro element as a requirement. Personally I have found that you can do whatever you want in a shell script... I think keeping things centrally generally makes readability for the next person to do your job easier. But both ways are okay

anyways, in regards to your original question, why couldn't you use the following?

Code:
#!/usr/bin/ksh
clear

TSM=$1
TSM_PSWD=/home/xxxx/pwdfile
TSM_CMD=dsmadmc
read ID PASSWORD < ${TSM_PSWD}
tsmCMD="${TSM_CMD} -id=${ID} -pa=${PASSWORD} -se=$TSM -dataonly=yes -comma"


$tsmCMD "query volume A00002L3
format=detailed"

it does not require the continuation character... another example with it used is the following select...

Code:
#!/usr/bin/ksh
clear

TSM="$1"
TSM_PSWD=/home/xxxx/pwdfile
TSM_CMD=dsmadmc
read ID PASSWORD < ${TSM_PSWD}
tsmCMD="${TSM_CMD} -id=${ID} -pa=${PASSWORD} -se=$TSM -dataonly=yes -comma"


$tsmCMD "select node_name, domain_name, scheduled_start, status, reason \
from events  \
where scheduled_start>='1901-01-01' \
and scheduled_start>=current_timestamp - $2 hours \
and status!='Completed'"
 
Mateinone,

Thanks for your simple and elegant solutions to both examples.

DeanY
 
Back
Top