In earlier articles, we’ve become familiar with running one-off CLI commands or sequences of commands. Quite often, though, it is useful to be able to execute a set of CLI commands from a server/desktop/laptop to instruct the Storwize system to carry out a number of tasks.
A common requirement is to have Flashcopy commands sent from a host system to the Storwize during or as part of an overnight batch process. Storwize does not allow us to store scripts so we need to have the scripts on our server and then send those scripts to the Storwize CLI for processing.
Imagine we’ve had a request to create a clone of an IBM i LPAR which has 160 volumes mapped to it. Creating a clone for all these volumes is possible on the GUI but it will take you some time. With the CLI, however, we can achieve this is a very short space of time.
This is not something we’re likely to do on a regular basis so we don’t need anything complicated to get this to work. Here’s a script I use to achieve this:
I created this in my favourite Windows/Linux editor and saved it for later use. To execute this script, I would:
1. Change the source and target variables, e.g.
2. Select the entire script <CTLT+A> and copy it <CTRL+C>
3. Paste the script directly into my Putty or ssh terminal on my Storwize CLI session
Now the script will execute.
Automating script execution
What if we want to run a script multiple times or on a regular basis?
As I mentioned previously, we cannot store CLI scripts on Storwize so we need to store and submit our scripts from a system that has SSH client support. Linux, AIX and IBM i all have support for OpenSSH so these are all valid operating systems to use for script storage and execution to our Storwize system. Windows requires additional software to support ssh. The two options I use are OpenSSH in Cygwin or Putty.
Many people will be familiar with Putty. There is an additional Putty download called Plink which will allow you send and execute a script file on a remote ssh server.
To use this method, you need to create a file on your server/desktop/laptop with all the commands you need to execute using a function called a HERE file. Take a look at this script call v7000.sh:
The script defines a variable call, COMMANDS. This variable is used to hold all the commands we want to run on the Storwize CLI. Each command must be separated by a semi-colon. All the commands are surrounded by parentheses.
Note the use of EOF at the start and end of the variable. These are important as they define the start and end of the commands. This is what we call a HERE file.
With the COMMANDS variable defined, we then execute the ssh command which connects to the Storwize CLI as user “superuser” and then passes the COMMANDS variable which contains the commands to execute.
A note for IBM i users. You can use this method by executing the script from with PASE using IBM Portable Utilities for i (5733-SC1). Both of these are provided on your standard install media and are non-chargeable options.
Although I can use the method above in Windows using OpenSSH provided by Cygwin, I can also use Putty Plink. Putty Plink can be used to execute a single command or submit the commands in a file.
The following command will log in to my Storwize system as superuser and then run the lsvdisk command. This is executed from a Windows CMD session. As soon as the command is complete, the ssh session is closed.
It is possible to write a Windows batch program to execute multiple Storwize commands:
The main issue with this is speed. The batch file has a loop, from 1 to 60. Inside that loop we have two Plink commands. This means that the batch program will log into the Storwize CLI 120 times.
To make this more efficient, we can store our script in a file in the Windows file system and have Plink send the lines in the file as if you were using the copy and paste method I described earlier.
If I have a file c:\users\robinsg\Documents\scripts\chgprim.bat containing:
I can use the following Plink command to execute the script:
As you can see, by using Plink’s -m option I can tell it to send and execute the contents of the file. This time Plink will execute the ssh login to the Storwize CLI only once.
I have been collecting some handy one-liners for the Storwize CLI. These can be viewed here on IBM DeveloperWorks.
PartnerWorld: IBM Portable Utilities for i web page.
SVC and V7000 Scripting on DeveloperWorks.