0、先设置root的环境变量:export PATH=/usr/sfw/bin:/usr/ccs/bin:$PATH
1、安装tcl
下载tcl8.6.13-src.tar.gz文件
下载网站:
gunzip tcl8.6.13-src.tar.gz
tar -xvf tcl8.6.13-src.tar
cd tcl8.6.13/unix
mkdir solaris
cd solaris/
../configure --prefix=/data/expect_local --exec-prefix=/data/expect_local/solaris-sparc
make
make install
2、安装expect
下载expect5.45.4.tar.gz
下载网址:
gunzip expect5.45.4.tar.gz
tar -xvf expect5.45.4.tar
cd expect5.45.4
bash-3.2# find / -name [tclConfig.sh]() /usr/sfw/lib/tclConfig.sh /usr/local/solaris-x86/lib/tclConfig.sh /data/sftp/tcl8.6.13/unix/soalris/tclConfig.sh
./configure --help
./configure --with-tcl=/data/sftp/tcl8.6.13/unix/solaris/ --prefix=/data/expect_local --exec-prefix=/data/expect_local/solaris-sparc
make
make install
修改/data/expect_local权限为755,其他用户可以使用expect。
sftp脚本示例:注意不能识别$符号
bash-3.2# more sftp.sh
/data/expect_local/solaris-sparc/bin/expect << EOF
spawn sftp username@ipaddress
set timeout 60
expect {
"(yes/no)" {send "yes\r"; exp_continue}
"*assword:" {send "password\r"}
}
expect "sftp>"
send "cd /tmp\r"
expect "sftp>"
send "lcd /tmp\r"
expect "sftp>"
send "exit\r"
EOF