这个expect脚本是为了获取线上服务器的容量大小,并无实际意义
#!/usr/bin/expect
set timeout 60 #设置超时
set user [lindex $argv 0] #设置第一个参数
set password [lindex $argv 1]
set ipaddr [lindex $argv 2]
set port [lindex $argv 3]
set mypassword [lindex $argv 4]
spawn ssh [email protected]$ipaddr -p $port #远程连接ssh
expect {
"(yes/no)" { send "yes\r"; exp_continue }
"password:" { send "$password\r" }
}
expect [email protected]* {send " df -h > $ipaddr.disk.rocky \r" } ;
expect [email protected]* {send " df -ih >> $ipaddr.disk.rocky \r"}
#expect [email protected]* {send " scp -P 8026 *.rocky [email protected]:/home/rockycai/ip_file/$ipaddr/ \r" } ;
#expect {
# "(yes/no)" { send "yes\r"; exp_continue }
# "password:" { send "$mypassword\r" }
#}
expect [email protected]* {send " rm -rf *.rocky \r"}
expect [email protected]* {send " exit \r" } ;
#spawn /home/rockycai/ssh/autoDemo.sh $ipaddr
expect eof ;
可以根据实际情况来更改需求