[Script Help] Login to TSM Server to Gather Information

LiamRobson

ADSM.ORG Member
Joined
Sep 12, 2016
Messages
10
Reaction score
0
Points
0
PREDATAR Control23

Hi,

I need a little help with a script. I need to be able to do the following:
  1. Login to a server (I work with 8 TSM instances) with a given username and password.
  2. Run a script (run scratch-count is already created on the server) to see how many scratch tapes are available.
  3. Pipe the output of the script to a local directory (C:\TSM\scratch_count) with a date stamp (C:\TSM\scratch_count\scratchcount-01011970.txt) for example.
I'm pretty new to TSM and cant find anything online that really comes close to this. I will be running the script on a Windows box also. Any help would be great.

Thanks.
 
PREDATAR Control23

You said you have 8 TSM instances - are these all having their own tape libraries? Or, are these pointed to a Library Manager?

If you have the latter, you only need to query the Library manager as the scratch count does not flow back to the library clients.

In any regards, here are the steps you need to achieve your goal:

Code:
1. Install the full TSM BA Client on your desktop - this means you need the dsmadmc.exe installed
2. Create an empty file called dsm.opt in C:\Program Files\Tivoli\TSM\baclient
3. Create C:\TSM - mkdir c:\TSM
4. Create a file called srvr.txt in C:\Program Files\Tivoli\TSM\baclient for which srvr.txt list the TSM Instances one line each (this is assuming TCPPort=1500 for all TSM servers)
5. Create a batch file, say scratch.cmd, in C:\Program Files\Tivoli\TSM\baclient

@echo off

for /F %%i in (srvr.txt) do (
echo Scratch count for %%i on %DATE% >> c:\TSM\scratch_count
dsmadmc.exe /tcpserveraddress=%%i /id=admin /pa=admin_password -noc -dataonly=yes "run scratch-count" >> c:\TSM\scratch_count
echo >> c:\TSM\scratch_count
)
 
Last edited:
PREDATAR Control23

Each TSM instance has a script called 'scratch-count' which looks at VLS and ESL libraries and gives the output of status 'Scratch'. The script I require needs to login to the server, run the script 'Sratch-Count' and pipe the output to a directory with a date stamp. The script above looks to do the job. The srvr.txt file, does this just need to hold the IP address on line 1 like 192.168.0.1 for example?
 
PREDATAR Control23

UPDATE: Scripts works a treat, thank you!

I've added a datestamp variable into the script which renames the file scratch_count_21.03.2017.txt. My questions is, if i put the .cmd file into task scheduler, run it daily at 08:00am, will it create a new file, or overwrite the file that already exists? I would like each file to be specific to each day, is that how this will work?
 
PREDATAR Control23

will it create a new file, or overwrite the file that already exists?
>> creates/appends
> creates/overwrites
I would like each file to be specific to each day, is that how this will work?
If you give it a new name each time by putting a variable in the name that changes everytime, you will end up with a new file each time.

Depending on what your needs are, you could slightly modify moon-buddy's script and append to a .CSV file instead that you can open in Excel and then do all sorts of manipulations:


Code:
for /F %%i in (srvr.txt) do (dsmadmc.exe -tcpserveraddress=%%i -id=admin -pa=password -noc -dataonly=yes -comma "select date(current_date),'%%i' ,library_name,count(*) from libvolumes where status='Scratch' group by library_name") >> scratch.csv
This will create a spreadsheet with 4 columns: date, servername, library name, scratch count
The servername will be the values you put in srvr.txt.

It will append to it every time the batch file runs and look something like this.
upload_2017-3-21_9-26-46.png
 
PREDATAR Control23

UPDATE: Scripts works a treat, thank you!

I've added a datestamp variable into the script which renames the file scratch_count_21.03.2017.txt. My questions is, if i put the .cmd file into task scheduler, run it daily at 08:00am, will it create a new file, or overwrite the file that already exists? I would like each file to be specific to each day, is that how this will work?

Since the output file is renamed specific to the day it was run, then the output files are unique.

If you create a shortcut to the CMD file and set the starting location as C:\Program Files\Tivoli\TSM\baclient, then you can use this shortcut when you define a daily scheduler.

Yes, you can use the IP address per line:

192.168.2.5
192.168.2.10
etc
 
Last edited:
PREDATAR Control23

That's not your question, but it may interest you anyway. If you have the Operation Center configured and running, you can send yourself (or others) with a daily report of scratch tapes by server and library.
upload_2017-3-21_9-41-31.png

The email will look something like this:

upload_2017-3-21_9-40-40.png
 
PREDATAR Control23

>> creates/appends
> creates/overwrites
If you give it a new name each time by putting a variable in the name that changes everytime, you will end up with a new file each time.

Depending on what your needs are, you could slightly modify moon-buddy's script and append to a .CSV file instead that you can open in Excel and then do all sorts of manipulations:


Code:
for /F %%i in (srvr.txt) do (dsmadmc.exe -tcpserveraddress=%%i -id=admin -pa=password -noc -dataonly=yes -comma "select date(current_date),'%%i' ,library_name,count(*) from libvolumes where status='Scratch' group by library_name") >> scratch.csv
This will create a spreadsheet with 4 columns: date, servername, library name, scratch count
The servername will be the values you put in srvr.txt.

It will append to it every time the batch file runs and look something like this.
View attachment 1264

I have made another .cmd file for the .csv output, ran it and it output the following:

Untitled.png

How can I remove lines 1 - 10 leaving just the date, server name (blanked out with srvr) library name (ESLXX, VLSXX) and scratch count (163,280)? Also, is there a way to add headings to each column?

Date Server Library Scratch Tapes
21/03/2017 srvr ESL1 163
21/03/2017 srvr VLS1 280
 
PREDATAR Control23

Check the options both moon-buddy and I used in our dsmadmc commands. (-dataonly -comma)

If you append to the file, just edit the .csv file once and save it.

If you create a new one each time, just do:

Code:
echo column1,column2,column3,column4 > output.csv
dsmadmc ... >> output.csv
 
PREDATAR Control23

UPDATE:
Nearly there with it all. Some of the servers i have connect on port 1500 so using 'for /F %%i in (srvr.txt) do (' works just fine. However, some servers i have connect on port 1510 and 1511 for some reason. Can i create another text file (srvrports.txt) and call this some how? or another elegant way to connect to all 8 servers with different IP's and ports?
 
PREDATAR Control23

Modify the srvr.txt like:

Code:
192.168.2.5;1510
192.168.2.10;1511
etc

modify my script like:

Code:
@echo off

for /F "tokens=1,2* delims=; " %%i in (srvr.txt) do (
echo Scratch count for %%i on %DATE% >> c:\TSM\scratch_count
dsmadmc.exe /tcpserveraddress=%%i /tcpport=%%j /id=admin /pa=admin_password -noc -dataonly=yes "run scratch-count" >> c:\TSM\scratch_count
echo >> c:\TSM\scratch_count
)
 
PREDATAR Control23

Modify the srvr.txt like:

Code:
192.168.2.5;1510
192.168.2.10;1511
etc

modify my script like:

Code:
@echo off

for /F "tokens=1,2* delims=; " %%i in (srvr.txt) do (
echo Scratch count for %%i on %DATE% >> c:\TSM\scratch_count
dsmadmc.exe /tcpserveraddress=%%i /tcpport=%%j /id=admin /pa=admin_password -noc -dataonly=yes "run scratch-count" >> c:\TSM\scratch_count
echo >> c:\TSM\scratch_count
)

Thanks, added, and ran, get the following error "ANS8017E Command line parameter 2: 'tcpport=-' is no valid"

srvr.txt looks like:
192.168.0.1;1500
192.168.0.2;1510
192.168.0.3;1511

could it be an issue with /tcpport=%%j and %%j not being present?
 
PREDATAR Control23

Thanks, added, and ran, get the following error "ANS8017E Command line parameter 2: 'tcpport=-' is no valid"

srvr.txt looks like:
192.168.0.1;1500
192.168.0.2;1510
192.168.0.3;1511

could it be an issue with /tcpport=%%j and %%j not being present?

The syntax is correct - here is the result of the following:

Code:
svrvr.txt:

192.168.0.1;1500
192.168.0.2;1510
192.168.0.3;1511

@echo off

for /F "tokens=1,2* delims=; " %%i in (srvr.txt) do (
echo Scratch count for %%i %%j on %DATE% >> test_out.txt
)

test_out.txt:

Scratch count for 192.168.0.1 1500 on Tue 03/21/2017
Scratch count for 192.168.0.2 1510 on Tue 03/21/2017
Scratch count for 192.168.0.3 1511 on Tue 03/21/2017

Did you copy and paste? Try entering the script manually. The %%j variable is automatically picked up by the script.

You can also try this:
Code:
@echo off

for /F "tokens=1,2* delims=; " %%i in (srvr.txt) do (
dsmadmc /tcpserveraddress=%%i /tcpport=%%j /id=admin /pa=password
)

which is will open a CLI session to each TSM server listed in srvr.txt and when you quit from the session will open the next one, etc.
 
PREDATAR Control23

In the srvr.txt file, i have listed the server hostname - IP;port (SRV1 - 192.168.0.1;1500) and id didnt like that, but liked it before adding the tcpport parameter. I've removed the 'hostname' and it works a treat, so a thank you for that.

Any way to include the hostname instead of the IP address in the output? Just makes it a little easier seeing the hostname rather than the IP address.
 
PREDATAR Control23

In the srvr.txt file, i have listed the server hostname - IP;port (SRV1 - 192.168.0.1;1500) and id didnt like that, but liked it before adding the tcpport parameter. I've removed the 'hostname' and it works a treat, so a thank you for that.

Any way to include the hostname instead of the IP address in the output? Just makes it a little easier seeing the hostname rather than the IP address.

If you have DNS entries for the host name, then you can just use the host names.
 
PREDATAR Control23

Any way to include the hostname instead of the IP address in the output? Just makes it a little easier seeing the hostname rather than the IP address.
Depending on your script on the server, you could put the servername in your query output.

Example, your SQL query could do this:
Code:
select date(current_date) as DATE,status.server_name,libvolumes.library_name,count(libvolumes.volume_name) as SCRATCH from libvolumes,status group by status.server_name,libvolumes.library_name
 
PREDATAR Control23

Moon-buddy, script works just fine. Changed the srvr.txt to use the hostname;port and it worked. Tested it in a scheduled task which also worked. Just need to add (if dir exists then foo else mkdir bar), any pointers on how to incorporate this into your script? If not, cheers for the help regardless :)
 
PREDATAR Control23

Moon-buddy, script works just fine. Changed the srvr.txt to use the hostname;port and it worked. Tested it in a scheduled task which also worked. Just need to add (if dir exists then foo else mkdir bar), any pointers on how to incorporate this into your script? If not, cheers for the help regardless :)

What do you mean by "add (if dir exists then foo else mkdir bar)"? Is it C:\TSM\?

If so:

Code:
@echo off
IF exist C:\TSM (
goto RESUME
) ELSE (
mkdir c:\TSM
)

:RESUME

for /F "tokens=1,2* delims=; " %%i in (srvr.txt) do (
echo Scratch count for %%i on %DATE% >> c:\TSM\scratch_count
dsmadmc.exe /tcpserveraddress=%%i /tcpport=%%j /id=admin /pa=admin_password -noc -dataonly=yes "run scratch-count" >> c:\TSM\scratch_count
echo >> c:\TSM\scratch_count
)
 
PREDATAR Control23

@moon-buddy: Sorry for the poor description, but yes, the above is what i needed :)

Final thing (promise):

The final script looks like the following:
Code:
for /F "tokens=1,2* delims=; " %%i in (srvr.txt) do (
(dsmadmc.exe /tcpserveraddress=%%i /tcpport=%%j /id=reporter /pa=reporter -noc -dataonly=yes -comma "select date(current_date),'%%i' ,library_name,count(*) from libvolumes where status='Scratch' group by library_name") >> %REPORTSDIR%\%YEAR%\%MONTHNAME%\%DATESTAMP%\"Daily Scratch Count".csv
)

The output from the script looks like the following:

Raw Data.png

Is there anyway to remove the ANS1691I messages from the outputted .csv? Just makes it a little easier then manually removing the lines each day.
 
PREDATAR Control23

Do you have any entry in the dsm.opt file?

If you have, delete all entries and leave the dsm.opt blank; dsm.opt MUST exist with no entries.

I further assume that you are executing this from your desktop.​
 
Top