網站首頁 編程語言 正文
場景:
shell腳本中,scp和ssh連接時,自動輸入用戶名和密碼。
解決方案:
例:
#!/bin/bash
remoteIp=IP
remoteUser=用戶名
remotePw=密碼
function download(){
? remoteFile=$1
? localDir=$2
? expect << EOF
? ? set timeout 1200;
? ? spawn scp -r -p $remoteUser@$remoteIp:"$remoteFile" "$localDir"
? ? expect{
? ? ? "*yes/no*" {send "yes\n";exp_continue}
? ? ? "*Permission denied*" {exit 1}
? ? ? "*password*" {send "$remotePw\n";exp_continue}
? ? ? "*Killed by signal 1" {exit 1}
? ? }
EOF
}
fucntion remoteCmd(){
? cmd=$1
? expect << EOF
? ? set timeout 1200;
? ? spawn ssh $remoteUser@$remoteIp
? ? expect{
? ? ? "*yes/no*" {send "yes\n";exp_continue}
? ? ? "*Permission denied*" {exit 1}
? ? ? "*password*" {send "$remotePw\n";exp_continue}
? ? ? "*\$ " {send "\n"}
? ? }
? ? expect "*\$ " {send "$cmd\n"}
? ? expect "*\$ " {send "exit\n"}
EOF
}
remoteCmd "ls -l"
原文鏈接:https://blog.csdn.net/hnht1989/article/details/127591909
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-12-08 Apache?Cordova?Android原理應用實例詳解_Android
- 2023-01-07 Android開發X?Y軸Board的繪制教程示例_Android
- 2022-10-11 python格式化字符串的實戰教程(使用占位符、format方法)_python
- 2021-12-07 Centos8搭建基于kdc加密的nfs_Linux
- 2022-08-17 python+pytest接口自動化之session會話保持的實現_python
- 2022-01-03 踩坑解決mongoose對已經存在的集合查詢,查詢條件不起限制作用的問題
- 2022-10-24 Python?NumPy教程之數據類型對象詳解_python
- 2023-03-16 windows下Docker部署Flask的詳細教程_docker
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支