I'm trying to work with Python and automate some tasks in IBM Spectrum Protect (A.K.A. TSM) tool. Normally, I would open a CMD with Admin privileges, change directory to where I have a Batch file for "TSM Administrative CLI tool", select the batch file and run.
The batch file (Name: TSM_Server_CLI.bat) contains the following:
@@echo Off
set OptFile="C:\tsm\config\dsm.opt"
call "Config\userConfig.bat"
%systemdrive%
cd "%programfiles%\Tivoli\TSM\baclient"
dsmadmc -optfile=%OptFile% -id=username
The "C:\tsm\config\dsm.opt" contains the TSM server information (Name, IP address). The "Config\userConfig.bat" only contains my userID. "set User="username"
Then, I would have to enter my password, but this can be saved in the batch file (-password=''), and then I start running TSM commands into the TSM server.
Now, I wanted to use Python to automate some of those commands and save an output file.
I'm able to open or run the batch file(TSM_Server_CLI.bat), which open a new CMD window, But I haven't found a way to send commands to that new CMD window or terminal, which is where I have to enter the TSM Commands.
tsm.py
os.chdir(r"C:\\tsm")
os.startfile("TSM_Server_CLI.bat")
I have found that "subprocess" module can help on this but I haven't found the correct script for it, and I'm not sure if this is even possible.
The plan is to have a series of commands in my python script to be send or executed into the CMD/terminal opened with "os.startfile".
For example:
- Open TSM_Server_CLI.bat, which open a CMD window.
- Run
query node > output.csv
- Run
query session >> output.csv
- etcetera.
I hope that explains my idea. thanks