initial commit

This commit is contained in:
Fabio Scotto di Santolo
2020-07-28 19:28:25 +02:00
commit 4cc88d2f6e
245 changed files with 22820 additions and 0 deletions

35
chapter8/boot-net-install.exp Executable file
View File

@@ -0,0 +1,35 @@
#!/usr/local/bin/expect -f
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn.t run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
set chassis [lindex $argv 0]
set blade [lindex $argv 1]
set timeout -1
spawn -noecho telnet $chassis
log_user 0
match_max 100000
expect "username: "
send -- "prodmgr\r"
expect -exact "prodmgr\r
password: "
send -- "Abc1234\r"
expect ">"
send -- "console -f $blade\r"
send -- "\r"
expect "ok"
send -- "boot net - install\r"
log_user 1
expect ""
send -- "logout\r"
send_user "\r\n"
exit
expect eof

101
chapter8/etc-hosts-copy.exp Executable file
View File

@@ -0,0 +1,101 @@
#!/usr/local/bin/expect -f
#
# SCRIPT: etc-hosts-copy.exp
# Set the timeout to 3 seconds
set timeout 3
# Assign the first command line argument to the
# "host" variable
set rem_host [lindex $argv 0]
# Spawn an ssh session to $host as the prodmgr user
spawn /usr/bin/ssh -l prodmgr ${rem_host}
# When we ssh to a remote server we can have two
# possible responses, 1) "*re you sure you want to continue
# connecting*", which we must reply to with "yes", and
# 2) Password: prompt. This next expect statement
# will perform the correct action based on the
# response.
expect {
"*re you sure you want to continue connecting*"
{
send "yes\n"
expect {
"*assword*"
{
send "Abc1234\n"
}
}
}
"*assword*"
{
send "Abc1234\n"
}
}
# Sleep for 1 second before proceeding
sleep 1
# Set the command-line prompt for the prodmgr user
# to the hash mark, #
send "PS1\=\"\# \"\n "
# Now we know what to expect as a command-line prompt
expect "^#*"
# Copy the master /etc/hosts file from yogi
# to this machine.
# First su to root
send "su - \n"
expect "*assword:*"
send "ABCD1234\n"
sleep 1
# Set the command-line prompt for the root user
# to the hash mark, #
send "PS1\=\"\# \"\n "
# Now we know what the command-line prompt is for
# the root user
expect "^#*"
# Save the current version of the /etc/hosts file
send "cp /etc/hosts /etc/hosts$$\n"
expect {
"*re you sure you want to continue connecting*"
{
send "yes\n"
expect {
"*assword*"
{
send "Abc1234\n"
}
}
}
"*assword*"
{
send "Abc1234\n"
}
"^#*"
{
send "\n"
}
}
# Copy the master /etc/hosts file from yogi to
# this server.
send "rcp yogi:/etc/hosts /etc/hosts \n"
expect "^#*"
# Logout from $host
send "exit\n"
expect eof

13
chapter8/findslot Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/bash
#
# SCRIPT: findslot
# PURPOSE: This script is used to locate a blade server
# within the specified SUN blade chassis.
#
CHAS=$1
HOST=$2
SLOT=`/usr/local/bin/showplatform.exp $CHAS \
| /usr/bin/grep $HOST | cut -f 1 -d " "`
echo $SLOT

View File

@@ -0,0 +1,33 @@
#!/usr/local/bin/expect -f
#
# SCRIPT: ftp-get-file-cmd-line.exp
#
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
set rem_host [lindex $argv 0]
set rem_dir [lindex $argv 1]
set rem_file [lindex $argv 2]
set timeout -1
spawn ftp $rem_host
match_max 100000
expect "Name *: "
send -- "prodmgr\r"
expect "Password:"
send -- "Abc1234\r"
expect "ftp>"
send -- "cd $rem_dir \r"
expect "ftp>"
send -- "get $rem_file \r"
expect "ftp>"
send -- "bye\r"
expect eof

30
chapter8/ftp-get-file.exp Executable file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/expect -f
#
# SCRIPT: ftp-get-file.exp
#
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
set timeout -1
spawn ftp yogi
match_max 100000
expect "Name *: "
send -- "prodmgr\r"
expect "Password:"
send -- "Abc1234\r"
expect "ftp>"
send -- "cd /scripts\r"
expect "ftp>"
send -- "get random_file.out\r"
expect "ftp>"
send -- "bye\r"
expect eof

4
chapter8/proc_increment_by_1 Executable file
View File

@@ -0,0 +1,4 @@
proc increment_by_1 { MY_COUNT } {
set MY_COUNT [expr $MY_COUNT + 1]
return "$MY_COUNT"
}

62
chapter8/showplatform.exp Executable file
View File

@@ -0,0 +1,62 @@
#!/usr/local/bin/expect -f
#
# This Expect script was generated by autoexpect on Mon Apr 2 09:44:34 2007
# Expect and autoexpect were both written by Don Libes, NIST.
#
# Note that autoexpect does not guarantee a working script. It
# necessarily has to guess about certain things. Two reasons a script
# might fail are:
#
# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,
# etc.) and devices discard or ignore keystrokes that arrive "too
# quickly" after prompts. If you find your new script hanging up at
# one spot, try adding a short sleep just before the previous send.
# Setting "force_conservative" to 1 (see below) makes Expect do this
# automatically - pausing briefly before sending each character. This
# pacifies every program I know of. The -c flag makes the script do
# this in the first place. The -C flag allows you to define a
# character to toggle this mode off and on.
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
#
# 2) differing output - Some programs produce different output each time
# they run. The "date" command is an obvious example. Another is
# ftp, if it produces throughput statistics at the end of a file
# transfer. If this causes a problem, delete these patterns or replace
# them with wildcards. An alternative is to use the -p flag (for
# "prompt") which makes Expect only look for the last line of output
# (i.e., the prompt). The -P flag allows you to define a character to
# toggle this mode off and on.
#
# Read the man page for more info.
#
# -Don
set chassis [lindex $argv 0]
set timeout -1
spawn $env(SHELL)
send -- "telnet ${chassis}\r"
expect -exact "telnet ${host}\r"
expect -exact "username: "
send -- "prodmgr\r"
expect -exact "prodmgr\r
password: "
send -- "Abc1234\r"
expect -exact "\r
${host}>"
send -- "showplatform -v\r"
expect -exact "showplatform -v\r"
send -- "logout\r"
expect -exact "logout\r"
exit
expect eof