This section describes the installation and use of scripts to set up access to the VTL CLI without passwords. It consists of the following subsections:
You can install scripts to operate in either the Linux and Solaris environments or in the Windows environment.
Check to see if an Expect package and SSH software are already installed on your system. If not, check to see if they are on the Linux or Solaris installation CD or if they are available from the distributor. (Installing the Expect package also should install the TCL package that is a required dependency.)
Install the Expect package for Windows. The package can be downloaded from http://bmrc.berkeley.edu/people/chaffee/expectnt.html.
Install the OpenSSH client package for Windows. The package can be downloaded from http://sshwindows.sourceforge.net/download/.
In the Expect script, change the path to the Expect and SSH programs based on where the Expect package was installed earlier. This section consists of the following subsections:
To modify the script to suit the needs of your environment, change the first line in the script (#!/usr/local/bin/expect) to something like #!/path/to/expect.
Similarly, change the line set ssh /usr/bin/sshto something like set ssh /path/to/ssh.
The following text is a sample script for a Linux or Solaris environment:
#!/usr/local/bin/expect
set ssh /usr/bin/ssh
set timeout -1
set username "admin"
set password "NetApp"
set command "help"
if {$argc < 1 || $argc > 4} {
puts "Usage: $argv0 <vtl> \[\"command\"\] \[password\] \[username\]"
puts "ssh \[username\]:\[password\]@<vtl> \[\"command\"\]"
puts "Defaults: "
puts " command = $command"
puts " password = $password"
puts " username = $username"
exit 1
}
set vtl [lindex $argv 0]
if {[string length [lindex $argv 1]] != 0} {
set command [lindex $argv 1]
}
if {[string length [lindex $argv 2]] != 0} {
set password [lindex $argv 2]
}
if {[string length [lindex $argv 3]] != 0} {
set username [lindex $argv 3]
}
spawn $ssh -o NumberOfPasswordPrompts=1 $username@$vtl $command
while {1} {
expect {
-ex "ssh: $vtl: Name or service not known" {
expect eof
exit 1
} -ex "Are you sure you want to continue connecting (yes/no)?" {
send -- "yes\r"
} -ex "$username@$vtl's password:" {
send -- "$password\r"
break
}
}
}
while {1} {
expect {
-ex "Permission denied." {
expect eof
exit 2
} -re "Error: " {
expect eof
exit 100
} eof {
exit 0
}
}
}
To modify the script to suit the needs of your environment, change the line set ssh "C:\\Program Files\\OpenSSH\\bin\\ssh.exe" to set ssh "C:\\Path To\\OpenSSH\\bin\\ssh.exe" depending on where the OpenSSH client was installed earlier.
The following text is a sample script for the Windows platform:
set ssh "C:\\Program Files\\OpenSSH\\bin\\ssh.exe"
set timeout -1
set username "admin"
set password "NetApp"
set command "help"
if {$argc < 1 || $argc > 4} {
puts "Usage: $argv0 <vtl> \[\"command\"\] \[password\] \[username\]"
puts "ssh \[username\]:\[password\]@<vtl> \[\"command\"\]"
puts "Defaults: "
puts " command = $command"
puts " password = $password"
puts " username = $username"
exit 1
}
set vtl [lindex $argv 0]
if {[string length [lindex $argv 1]] != 0} {
set command [lindex $argv 1]
}
if {[string length [lindex $argv 2]] != 0} {
set password [lindex $argv 2]
}
if {[string length [lindex $argv 3]] != 0} {
set username [lindex $argv 3]
}
spawn $ssh -o NumberOfPasswordPrompts=1 $username@$vtl $command
while {1} {
expect {
-ex "ssh: $vtl: Name or service not known" {
expect eof
exit 1
} -ex "Are you sure you want to continue connecting (yes/no)?" {
send -- "yes\r"
} -ex "$username@$vtl's password:" {
send -- "$password\r"
break
}
}
}
while {1} {
expect {
-ex "Permission denied." {
expect eof
exit 2
} -re "Error: " {
expect eof
exit 100
} eof {
exit 0
}
}
}
#!/bin/sh
POLL_INTERVAL=60
if [ $# -lt 2 ]
then
echo 1>&2 "Usage: $0 <vtl> <vtape> [interval]"
echo 1>&2 "Exports <vtape> from <vtl>. Polls once every \
[interval] seconds for completion"
echo 1>&2 "Defaults:"
echo 1>&2 " interval = 60"
exit 1
fi
VTL=$1
NO_PASSWD_CMD="./unix.exp $VTL"
VTAPE=$2
if [ -n $3 ]
then
POLL_INTERVAL=$3
fi
$NO_PASSWD_CMD "vlib export $VTAPE"
if [ $? -ne 0 ]
then
echo "Error exporting $VTAPE from $VTL"
exit 1
fi
while sleep $POLL_INTERVAL
do
$NO_PASSWD_CMD "iereq show" | grep "State: transferring data"
if [ $? -eq 1 ]
then
echo "Export of $VTAPE from $VTL is complete"
# email the admin that the physical tape is ready to
# be collected.
break
fi
done
exit 0
If you are working in a Linux or Solaris environment, run the script by entering the following command:
$ ./unix.exp <vtl> ["command"] [password] [username]
The username, password, and command values default to admin, NetApp, and help, respectively.
If you are working in a Windows environment, run the script by entering the following command:
C:\Scripts> "C:\Expect-5.2\bin\expect.exe" windows.exp <vtl> <command>
If the command syntax includes spaces (for example, network show or vlib list), type the command within double quotes, as shown:
"network show" / "vlib list")
The resulting output can be piped to other common utilities, such as grep, sed, cut, and further processed.
If the command is successful, the script exits with an exit status of 0. (This can be checked by using the $? variable in Linux and Solaris.) One of the following non-zero values is returned if an error occurs:
If the VTL host is not reachable, the exit status is 1.
If the password is incorrect, the exit status is 2.
If there is an error in the command invocation, the exit status is 100.
Copyright © 1994-2006, Network Appliance, Inc. All rights reserved.
Part number 210-03617_A0
Comments