侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

shell ssh 批量登录。执行shell脚本

2023-11-04 星期六 / 0 评论 / 0 点赞 / 32 阅读 / 1316 字

#!/bin/bash #批量ssh认证建立 for p in $(cat yq.txt) #注意ip.txt文件的绝对路径 do ip=$(echo "$p"|cut -f1 -d":")

#!/bin/bash  
#批量ssh认证建立  
for p in $(cat yq.txt)  #注意ip.txt文件的绝对路径  
do  
ip=$(echo "$p"|cut -f1 -d":")       #取ip.txt文件中的ip地址  
password=$(echo "$p"|cut -f2 -d":") #取ip.txt文件中的密码  
 
#expect自动交互开始  
expect -c " 
spawn scp /root/.ssh/id_rsa.pub root@$ip  
        expect {   
                /"*yes/no*/" {send /"yes/r/"; exp_continue}   
                /"*password*/" {send /"$password/r/"; exp_continue}   
                /"*Password*/" {send /"$password/r/";}   
        }   
"   
done   
 
#通过ssh批量执行命令  
 
for h in $(cat yq.txt|cut -f1 -d":")  
do
ssh root@$h '/data1/1.sh'    
#如果命令是多行的,请参照下面  
#ssh root@$h 'df -h' 
#ssh root@$h 'free -g' 
#ssh root@$h '此处写要执行的命令3' 
done  

广告 广告

评论区