Batch script output problem

John22439

ADSM.ORG Member
Joined
Jan 3, 2007
Messages
60
Reaction score
0
Points
0
Website
Visit site
Good morning All!

I was wondering if anyone can explain why my script does not create any output other than "in new file" ??

I am running this on a windows box connecting to an MVS TSM Server. I have other batch files that do work. My theory is that you cannot do mathematical calculations in a batch script?

Here is my script - the SQL works fine in a command console
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@echo off

set today=%date:~10,4%-%date:~4,2%-%date:~7,2%
set t2=%time:~0,5%

if not exist D:\output/sessions/ses_Mbps_%today%.txt goto CREATE_FILE
(same as below with chevrons to output to ... D:\output/sessions/ses_Mbps_%today%.txt)
goto END


:CREATE_FILE
echo %t2% > D:\output/sessions/ses_Mbps_%today%.txt
echo in new file > D:\output/sessions/ses_Mbps_%today%.txt
dsmadmc -id=TSM_TOOL -password=TSM_TOOL "select session_id,client_name,state,(cast((current_timestamp-start_time)minutes as decimal(10,0))),(cast((cast((((bytes_sent*8 )/1024)/1024) as decimal(18,0)) /cast((current_timestamp-start_time)seconds as decimal(18,0))) as INT)),(cast(cast((((bytes_received*8 )/1024)/1024) as decimal(18,0)) /cast((current_timestamp-start_time)seconds as decimal(18,0)) as INT)) from sessions" >> D:\output/sessions/ses_Mbps_%today%.txt


:END


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




The ADMIN script that I run on the TSM Server works fine (below) but I am trying to record the data on an hourly basis.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

select session_id,client_name,state,cast((current_timestamp-start_time)minutes as decimal(10,0)) as "Elapsed minutes",cast((cast((((bytes_sent*8 )/1024)/1024) as decimal(18,0)) /cast((current_timestamp-start_time)seconds as decimal(18,0))) as INT) as "Mbps sent",cast(cast((((bytes_received*8 )/1024)/1024) as decimal(18,0)) /cast((current_timestamp-start_time)seconds as decimal(18,0)) as INT) as "Mbps recvd" from sessions

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Any help or knowledge would be great!

Cheers,
j
 
:CREATE_FILE
echo %t2% > D:\output/sessions/ses_Mbps_%today%.txt
echo in new file > D:\output/sessions/ses_Mbps_%today%.txt
dsmadmc -id=TSM_TOOL -password=TSM_TOOL "select session_id,client_name,state,(cast((current_timest amp-start_time)minutes as decimal(10,0))),(cast((cast((((bytes_sent*8 )/1024)/1024) as decimal(18,0)) /cast((current_timestamp-start_time)seconds as decimal(18,0))) as INT)),(cast(cast((((bytes_received*8 )/1024)/1024) as decimal(18,0)) /cast((current_timestamp-start_time)seconds as decimal(18,0)) as INT)) from sessions" >> D:\output/sessions/ses_Mbps_%today%.txt

Change to:

:CREATE_FILE
echo %t2% > D:\output/sessions/ses_Mbps_%today%.txt

echo >> D:\output/sessions/ses_Mbps_%today%.txt

dsmadmc -id=TSM_TOOL -password=TSM_TOOL "select session_id,client_name,state,(cast((current_timest amp-start_time)minutes as decimal(10,0))),(cast((cast((((bytes_sent*8 )/1024)/1024) as decimal(18,0)) /cast((current_timestamp-start_time)seconds as decimal(18,0))) as INT)),(cast(cast((((bytes_received*8 )/1024)/1024) as decimal(18,0)) /cast((current_timestamp-start_time)seconds as decimal(18,0)) as INT)) from sessions" >> D:\output/sessions/ses_Mbps_%today%.txt

and be sure that this is executed in the directory that dsmadmc lies in. I hope that the user ID (TSM_TOOL) you are using has system privileges.
 
Hi moon_buddy, thanks for the quick response!

Yes the account is good - I use it for many other script that actually work.

I tried your solution and it did not work - but I'm still unsure why you would add a blank "ECHO" ?

Have you test this on your system?

Cheers,
j
 
Hi moon_buddy, thanks for the quick response!

Yes the account is good - I use it for many other script that actually work.

I tried your solution and it did not work - but I'm still unsure why you would add a blank "ECHO" ?

Have you test this on your system?

Cheers,
j

The blank echo just gives you a space in-between the first and second line that uses the select statement.

If you are wondering if the select statement works, I have not tested it. If it does not work, it maybe a syntax problem. Have you tried running it when a command line is open?

On another note, calculations do work in batch scripts given that is is being done by the select statement run under TSM and not by the batch script.
 
.....
If you are wondering if the select statement works, I have not tested it. If it does not work, it maybe a syntax problem. Have you tried running it when a command line is open?

Actually yes it does work, I've tried it in a console and through the TSM GUI as an ADMIN script.

So as far as I can see the syntax is good. The output to the text file just does not match the output to screen in the console. ???

j
 
So as far as I can see the syntax is good. The output to the text file just does not match the output to screen in the console. ???

Can you post the output for both running it manually and using the script? You don't have to put all of the output just the portions that you think are different.
 
Okidoki...

This is from the console:

tsm: TSM_SRV1>

tsm: TSM_SRV1>select session_id as "Session",client_name as "Client",state as "Ses State",cast((current_timestamp-start_time)minutes as decimal(10,0)) as "Elapsed minutes",cast((cast((((bytes_sent*8 )/1024)/1024) as decimal(18,0)) cast((current_timestamp-start_time)seconds as decimal(18,0))) as INT) as "Mbps sent",cast(cast((((bytes_received*8 )/1024)/1024) as decimal(18,0)) /cast((current_timestamp-start_time)seconds as decimal(18,0)) as INT) as "Mbps recvd" from sessions

Session Client Ses State Elapsed minutes Mbps sent Mbps recvd
----------- ------------------ ------------------ --------------- ----------- -----------
14991 ADMIN1 Run 1 0 0

tsm: TSM_SRV1>


This is the output from the text file:

"in new file "

And nothing else...

?? j ??



UPDATE: I ran the script twice to see what would happen...

OUTPUT:

in new file
14:14
ECHO is off.

Very wierd....
 
Last edited:
Try this:

@echo off

set today=%date:~10,4%-%date:~4,2%-%date:~7,2%
set t2=%time:~0,5%


IF NOT EXIST ses_Mbps_%today%.txt GOTO CREATE_FILE ELSE GOTO END


:CREATE_FILE

echo %t2% > ses_Mbps_%today%.txt

dsmadmc -id=<USER_ID> -password=<PASSWORD> -dataonly=yes -noconfirm "select session_id,client_name,state,(cast((current_timestamp-start_time)minutes as decimal(10,0))),(cast((cast((((bytes_sent*8 )/1024)/1024) as decimal(18,0)) /cast((current_timestamp-start_time)seconds as decimal(18,0))) as INT)),(cast(cast((((bytes_received*8 )/1024)/1024) as decimal(18,0)) /cast((current_timestamp-start_time)seconds as decimal(18,0)) as INT)) from sessions" >> ses_Mbps_%today%.txt


:END

I ran this under the directory where dsmadmc resides.
 
hmmmm....

I copied your script into a new file (moon.bat) and ran it.

15:09

The result was the current time???

j
 
This is what I got:

SESSION_ID CLIENT_NAME STATE Unnamed[4] Unnamed[5] Unnamed[6]
----------- ------------------ ------------------ ------------ ----------- -----------
1050 USERI IdleW 104 0 0
1782 USER2 IdleW 49 0 0
ANR2947E Division by zero was detected for operator '/'.

|
...............................V...............................
/1024)/1024) as decimal(18,0)) /cast((current_timestamp-start_t

ANS8001I Return code 26.
ANS8002I Highest return code was 26.

I guess the error is attributed to the fact that there is no data to process
 
Last edited:
This is what I got:

SESSION_ID CLIENT_NAME STATE Unnamed[4] Unnamed[5] Unnamed[6]
----------- ------------------ ------------------ ------------ ----------- -----------
1050 USERI IdleW 104 0 0
1782 USER2 IdleW 49 0 0
ANR2947E Division by zero was detected for operator '/'.

|
...............................V...............................
/1024)/1024) as decimal(18,0)) /cast((current_timestamp-start_t

ANS8001I Return code 26.
ANS8002I Highest return code was 26.

I guess the error is attributed to the fact that there is no data to process

That is truly bizarre....

What you got is what I am looking for... but you tried it in a batch file right? not in the console or GUI.... because if this is from a batch file I am stumped!?

j
 
That is truly bizarre....

What you got is what I am looking for... but you tried it in a batch file right? not in the console or GUI.... because if this is from a batch file I am stumped!?

j

Yes. Like what I posted. I run it in a batch file under the directory where dsmadmc resides.
 
Yes. Like what I posted. I run it in a batch file under the directory where dsmadmc resides.

Well... Thanks for all you efforts Ed.

Clearly there is something that I'm not doing right at my end.

If / when I find out what it is, I'll post the reason.

Cheers,
j
 
Worked for me too.

Can you copy and paste your script as it actually is at the moment? You don't have < or > around the username/password section do you? And you are deleting the output file before you try to run the script each time?
 
Worked for me too.

Can you copy and paste your script as it actually is at the moment? You don't have < or > around the username/password section do you? And you are deleting the output file before you try to run the script each time?

Hi BBB,

Below is the batch that I just ran...

my_batch.bat said:
@echo off

set today=%date:~10,4%-%date:~4,2%-%date:~7,2%
set t2=%time:~0,5%


IF NOT EXIST ses_Mbps_%today%.txt GOTO CREATE_FILE ELSE GOTO END


:CREATE_FILE

echo %t2% > ses_Mbps_%today%.txt

dsmadmc -id=xxxxxxx -password=yyyyyyy -dataonly=yes -noconfirm "select session_id,client_name,state,(cast((current_timestamp-start_time)minutes as decimal(10,0))),(cast((cast((((bytes_sent*8 )/1024)/1024) as decimal(18,0)) /cast((current_timestamp-start_time)seconds as decimal(18,0))) as INT)),(cast(cast((((bytes_received*8 )/1024)/1024) as decimal(18,0)) /cast((current_timestamp-start_time)seconds as decimal(18,0)) as INT)) from sessions" >> ses_Mbps_%today%.txt


:END

And the output was:

ses_Mbps_2009-03-13.txt said:

Which is the time I ran it - just now...

?????????????????????

I copied the select and pasted it in a console - and it works fine!

from my console said:
tsm: TSM1>select session_id,client_name,state,(cast((current_timestamp-start_time)minutes as decimal(10,0))),(cast((cast((((bytes_se
nt*8 )/1024)/1024) as decimal(18,0)) /cast((current_timestamp-start_time)seconds as decimal(18,0))) as INT)),(cast(cast((((bytes_receiv
ed*8 )/1024)/1024) as decimal(18,0)) /cast((current_timestamp-start_time)seconds as decimal(18,0)) as INT)) from sessions

SESSION_ID CLIENT_NAME STATE Unnamed[4] Unnamed[5] Unnamed[6]
----------- ------------------ ------------------ ------------ ----------- -----------
26502 CLIENT123 RecvW 251 0 104
26503 CLIENT123 RecvW 251 0 117
26505 CLIENT123 RecvW 251 0 116
26508 CLIENT123 RecvW 251 0 116
26780 CLIENT234 RecvW 189 0 22
27270 CLIENT345 IdleW 72 0 0
27271 CLIENT345 RecvW 72 0 32
27451 ME Run 6 0 0

tsm: TSM1>

Not sure why this is happening, I have all kinds of scripts that I run through my scheduler to collect all sorts of data... but this one eludes me.


j
 
Did you try your script without the time variables? Does it work then?

Nope.

But as I said I have some scripts that use all the elements above - and they work...

The only difference that I can see to date is that I do some calculations - this is the only script that I have that does this.


j
 
Back
Top