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   ~码铃薯~  阅读(34)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示