• Please help support our sponsors by considering their products and services.
    Our sponsors enable us to serve you with this high-speed Internet connection and fast webservers you are currently using at ADSM.ORG.
    They support this free flow of information and knowledge exchange service at no cost to you.

    Please welcome our latest sponsor Tectrade . We can show our appreciation by learning more about Tectrade Solutions
  • Community Tip: Please Give Thanks to Those Sharing Their Knowledge.

    If you receive helpful answer on this forum, please show thanks to the poster by clicking "LIKE" link for the answer that you found helpful.

  • Community Tip: Forum Rules (PLEASE CLICK HERE TO READ BEFORE POSTING)

    Click the link above to access ADSM.ORG Acceptable Use Policy and forum rules which should be observed when using this website. Violators may be banned from this website. This notice will disappear after you have made at least 3 posts.

[Script Help] Login to TSM Server to Gather Information

LiamRobson

ADSM.ORG Member
#1
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.
 

moon-buddy

ADSM.ORG Moderator
#2
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:

LiamRobson

ADSM.ORG Member
#3
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?
 

LiamRobson

ADSM.ORG Member
#4
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?
 

marclant

ADSM.ORG Moderator
#5
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
 

moon-buddy

ADSM.ORG Moderator
#6
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:

marclant

ADSM.ORG Moderator
#7
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
 

LiamRobson

ADSM.ORG Member
#8
>> 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
 

marclant

ADSM.ORG Moderator
#9
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
 

LiamRobson

ADSM.ORG Member
#10
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?
 

moon-buddy

ADSM.ORG Moderator
#11
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
)
 

LiamRobson

ADSM.ORG Member
#12
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?
 

moon-buddy

ADSM.ORG Moderator
#13
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.
 

LiamRobson

ADSM.ORG Member
#14
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.
 

moon-buddy

ADSM.ORG Moderator
#15
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.
 

marclant

ADSM.ORG Moderator
#16
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
 

LiamRobson

ADSM.ORG Member
#17
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 :)
 

moon-buddy

ADSM.ORG Moderator
#18
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
)
 

LiamRobson

ADSM.ORG Member
#19
@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.
 

moon-buddy

ADSM.ORG Moderator
#20
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.​
 

Advertise at ADSM.ORG

If you are reading this, so are your potential customer. Advertise at ADSM.ORG right now.

UpCloud high performance VPS at $5/month

Get started with $25 in credits on Cloud Servers. You must use link below to receive the credit. Use the promo to get upto 5 month of FREE Linux VPS.

The Spectrum Protect TLA (Three-Letter Acronym): ISP or something else?

  • Every product needs a TLA, Let's call it ISP (IBM Spectrum Protect).

    Votes: 7 23.3%
  • Keep using TSM for Spectrum Protect.

    Votes: 16 53.3%
  • Let's be formal and just say Spectrum Protect

    Votes: 4 13.3%
  • Other (please comement)

    Votes: 3 10.0%

Forum statistics

Threads
30,889
Messages
131,420
Members
21,194
Latest member
jamesmacd40