1. 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.
  2. 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

Discussion in 'Scripting' started by LiamRobson, Mar 20, 2017.

  1. LiamRobson

    LiamRobson ADSM.ORG Member

    Joined:
    Sep 12, 2016
    Messages:
    10
    Likes Received:
    0
    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.
     
  2.  
  3. moon-buddy

    moon-buddy ADSM.ORG Moderator

    Joined:
    Aug 24, 2005
    Messages:
    6,805
    Likes Received:
    358
    Occupation:
    Electronics Engineer, Security Professional
    Location:
    Somewhere in the US
    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: Mar 21, 2017
    LiamRobson likes this.
  4. LiamRobson

    LiamRobson ADSM.ORG Member

    Joined:
    Sep 12, 2016
    Messages:
    10
    Likes Received:
    0
    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?
     
  5. LiamRobson

    LiamRobson ADSM.ORG Member

    Joined:
    Sep 12, 2016
    Messages:
    10
    Likes Received:
    0
    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?
     
  6. marclant

    marclant ADSM.ORG Moderator

    Joined:
    Jun 16, 2006
    Messages:
    2,478
    Likes Received:
    348
    Occupation:
    Accelerated Value Specialist for Spectrum Protect
    Location:
    Canada
    >> 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.
    upload_2017-3-21_9-26-46.png
     
  7. moon-buddy

    moon-buddy ADSM.ORG Moderator

    Joined:
    Aug 24, 2005
    Messages:
    6,805
    Likes Received:
    358
    Occupation:
    Electronics Engineer, Security Professional
    Location:
    Somewhere in the US
    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: Mar 21, 2017
  8. marclant

    marclant ADSM.ORG Moderator

    Joined:
    Jun 16, 2006
    Messages:
    2,478
    Likes Received:
    348
    Occupation:
    Accelerated Value Specialist for Spectrum Protect
    Location:
    Canada
    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
     
  9. LiamRobson

    LiamRobson ADSM.ORG Member

    Joined:
    Sep 12, 2016
    Messages:
    10
    Likes Received:
    0
    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
     
  10. marclant

    marclant ADSM.ORG Moderator

    Joined:
    Jun 16, 2006
    Messages:
    2,478
    Likes Received:
    348
    Occupation:
    Accelerated Value Specialist for Spectrum Protect
    Location:
    Canada
    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
     
  11. LiamRobson

    LiamRobson ADSM.ORG Member

    Joined:
    Sep 12, 2016
    Messages:
    10
    Likes Received:
    0
    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?
     
  12. moon-buddy

    moon-buddy ADSM.ORG Moderator

    Joined:
    Aug 24, 2005
    Messages:
    6,805
    Likes Received:
    358
    Occupation:
    Electronics Engineer, Security Professional
    Location:
    Somewhere in the US
    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
    )
    
     
  13. LiamRobson

    LiamRobson ADSM.ORG Member

    Joined:
    Sep 12, 2016
    Messages:
    10
    Likes Received:
    0
    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?
     
  14. moon-buddy

    moon-buddy ADSM.ORG Moderator

    Joined:
    Aug 24, 2005
    Messages:
    6,805
    Likes Received:
    358
    Occupation:
    Electronics Engineer, Security Professional
    Location:
    Somewhere in the US
    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.
     
  15. LiamRobson

    LiamRobson ADSM.ORG Member

    Joined:
    Sep 12, 2016
    Messages:
    10
    Likes Received:
    0
    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.
     
  16. moon-buddy

    moon-buddy ADSM.ORG Moderator

    Joined:
    Aug 24, 2005
    Messages:
    6,805
    Likes Received:
    358
    Occupation:
    Electronics Engineer, Security Professional
    Location:
    Somewhere in the US
    If you have DNS entries for the host name, then you can just use the host names.
     
  17. marclant

    marclant ADSM.ORG Moderator

    Joined:
    Jun 16, 2006
    Messages:
    2,478
    Likes Received:
    348
    Occupation:
    Accelerated Value Specialist for Spectrum Protect
    Location:
    Canada
    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
     
  18. LiamRobson

    LiamRobson ADSM.ORG Member

    Joined:
    Sep 12, 2016
    Messages:
    10
    Likes Received:
    0
    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 :)
     
  19. moon-buddy

    moon-buddy ADSM.ORG Moderator

    Joined:
    Aug 24, 2005
    Messages:
    6,805
    Likes Received:
    358
    Occupation:
    Electronics Engineer, Security Professional
    Location:
    Somewhere in the US
    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
    )
    
     
  20. LiamRobson

    LiamRobson ADSM.ORG Member

    Joined:
    Sep 12, 2016
    Messages:
    10
    Likes Received:
    0
    @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.
     
  21. moon-buddy

    moon-buddy ADSM.ORG Moderator

    Joined:
    Aug 24, 2005
    Messages:
    6,805
    Likes Received:
    358
    Occupation:
    Electronics Engineer, Security Professional
    Location:
    Somewhere in the US
    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.​
     
    LiamRobson likes this.

Share This Page