功能:
服务器自动登陆BOSS应用服务器(10.222.109.7),登陆后用户也是poseidon
poseidon用户下执行 ./auto.sh
脚本:

auto.sh内容:
#!/usr/bin/expect
set timeout 60
#本机的root密码
set pass xxxx
#本机切换root,脚本放在/tmp目录下的
spawn su - root
expect {
"*Password:*" {send "$pass\r"}
}
expect "#*"
send "cd /home/poseidon/auto_ssh\r"
send "./auto_ssh.sh\r"
interact
auto_ssh.sh内容:
#!/usr/bin/expect
set timeout 60
#shh目标的信息
set hostname 10.123.123.7
set password w2s3d33
set username root
#ssh远程连接,自动带密码
spawn ssh $username@$hostname
expect {
"*password:*" { send "$password\r" }
}
expect "#*"
#远程切换目标目录
send "su - poseidon\r"
send "cd /app/boss\r"
send "pwd\r"
interact
浙公网安备 33010602011771号