1.编写脚本实现登陆远程主机。(使用expect和shell脚本两种形式)
编写脚本实现登陆远程主机。(使用expect和shell脚本两种形式)
1.expect 形式:
[root@CentOS8 ~]# cat remote_expect.sh
!/usr/bin/expect
********************************************************************
Author: buyaoming
QQ: 123456789
Date: 2022-07-14
FileName: remote_expect.sh
URL: www.haha.cn
Description: The test script
Copyright (C): 2022 All rights reserved
********************************************************************
set ip 10.0.0.7
set user root
set password 123456
set timeout 10
spawn ssh $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$password\n" }
}
interact
2.shell脚本形式
[root@CentOS8 ~]# cat remote_shell.sh
!/bin/bash
********************************************************************
Author: buyaoming
QQ: 123456789
Date: 2022-07-14
FileName: remote_shell.sh
URL: www.haha.cn
Description: The test script
Copyright (C): 2022 All rights reserved
********************************************************************
ip=10.0.0.6
user=root
password=123456
expect <<EOF
set timeout 10
spawn ssh $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$password\n" }
}
expect eof
EOF
~
执行:
· Blazor Hybrid适配到HarmonyOS系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· 解决跨域问题的这6种方案,真香!
· 分享4款.NET开源、免费、实用的商城系统
· 一套基于 Material Design 规范实现的 Blazor 和 Razor 通用组件库