HP StorageWorks 2300 Modular Smart Array CLI reference guide (500912-001, January 2009)

12 Using the CLI
Using CLI scripts
CLI commands can be scripted using a Telnet client like Expect or a Perl library.
The following example shows the Perl Expect script showfree.exp that starts a Telnet session, logs into
the CLI, executes a command to show free disks, and exits the CLI:
#!/usr/bin/expect
set login [lindex $argv 1]
set password [lindex $argv 2]
set host [lindex $argv 3]
set command [lindex $argv 4]
spawn telnet $host
expect "Login:"
send "$login\r"
expect "Password:"
send "$password\r"
send "$command\r"
send "exit"
expect eof
The following shows a possible result of executing this script:
$:./showfree.exp monitor !monitor 172.22.4.245 "show disks free"
Login: monitor
Password: ********
Product
System Name: Test
System Location: Lab
Version: version
# show disks free
ID Serial Number Vendor Rev How Used Type Size Rate(Gb/s) SP
---------------------------------------------------------------------------------
1.9 3NM4BAKV000098271CGD HP HPDA AVAIL SAS 146.8GB 3.0
1.10 3NM4GQ7Y00009824PYBD HP HPDA AVAIL SAS 146.8GB 3.0
1.16 K44ZT8325B29 ATA HPG1 AVAIL SATA-S 120.0GB 3.0 A
1.21 K44ZT8325B4G ATA HPG1 AVAIL SATA-S 120.0GB 1.5 A
---------------------------------------------------------------------------------
# exit