1、用shell脚本实现自动登录机器
#!/usr/bin/expect
#!/usr/bin/expect
set ip [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]
set timeout 15
spawn ssh $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$password\n" }
}
interact
#!/bin/bash
可以登录 但是登录后自动退出
#!/bin/bash
ip=$1
user=$2
password=$3
expect <<EOF
set timeout 15
spawn ssh $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$password\n" }
}
expect eof
EOF
2、shell 判断一个值bone是否在数组arrayZ=( one two three four five five )中
#!/bin/bash
declare -a arrayZ
arrayZ=( one two three four five )
bone="bone"