shell脚本学习

shell基本知识学习网址:https://www.bilibili.com/video/BV1hW41167NW?p=20&vd_source=273847a809b909b44923e3af1a7ef0b1

shell-expect知识学习网址:https://www.bilibili.com/video/BV1wW411K7Zy/?p=2&spm_id_from=pageDriver&vd_source=273847a809b909b44923e3af1a7ef0b1

  • 涉及脚本
#!/usr/bin/expect

set ipaddress "192.168.75.130"
set passwd "root"
set timeout 30

spawn ssh root@$ipaddress

expect {

"yes/no" { send "yes\r",exp_continue }
"password:" { send "$passwd\r" }

}

#加上下面这行代码,作用是:登录上远程主机之后不立即退出!!!
interact
shell脚本1
#!/usr/bin/expect

#使用位置参数的形式,让脚本编写更加灵活,适用范围更加广泛!!!
set ipaddress [ lindex $argv 0 ]
set user [ lindex $argv 1]
set passwd [ lindex $argv 2 ]

set timeout 30

spawn ssh $user@$ipaddress

expect {

"yes/no" { send "yes\r",exp_continue }
"password:" { send "$passwd\r" }

}

#加上下面这行代码,作用是:登录上远程主机之后不立即退出!!!
interact
shell脚本2

 

posted on 2022-09-24 11:18  ~码铃薯~  阅读(33)  评论(0编辑  收藏  举报

导航