網站首頁 編程語言 正文
場景:
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-09 Qt?自定義屬性Q_PROPERTY不顯示float類型的解決_C 語言
- 2022-07-22 定時任務和延時任務詳解
- 2022-01-29 調用存儲命令:將sqlserver表中的數據導出sql語句或生成insert into語句
- 2022-11-10 關于docker?cgroups資源限制的問題_docker
- 2022-03-21 SQL查詢連續登陸7天以上的用戶的方法實現_MsSql
- 2022-09-07 C語言函數調用約定和返回值詳情_C 語言
- 2023-07-08 qt修改默認構建路徑
- 2022-08-05 C語言簡明介紹指針的使用_C 語言
- 欄目分類
-
- 最近更新
-
- 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同步修改后的遠程分支