找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 661|回复: 0

SHELL编程密码远程拷贝文件脚本

[复制链接]

22

主题

21

回帖

148

积分

管理员

积分
148
发表于 2024-8-21 16:32:21 | 显示全部楼层 |阅读模式
1.1  SHELL编程密码远程拷贝文件脚本
  • 自动服务器IP和用户名、密码表:list.txt;
  • 自动安装expect远程交互工具;
  • 自动编写expect远程执行拷贝文件;
  • 支持任意文件远程拷贝操作;
  • 支持列表循环操作多个台服务器。

  1. <font size="4">#!/bin/bash
  2. #by author www.jfedu.net 2024
  3. #######################
  4. if
  5.       [ ! -e /usr/bin/expect ];then
  6.       yum  install expect -y
  7. fi
  8. #Judge passwd.txt exist
  9. if
  10.       [ ! -e ./passwd.txt ];then
  11.       echo -e "The passwd.txt is not exist......Please touch ./passwd.txt ,Content Example:\n192.168.1.11 passwd1\n192.168.1.12 passwd2"
  12.       sleep 2 &&exit 0
  13. fi
  14. #Auto Tuoch login.exp File
  15. cat>login.exp <<EOF
  16. #!/usr/bin/expect -f
  17. set ip [lindex \$argv 0]
  18. set passwd [lindex \$argv 1]
  19. set src_file [lindex \$argv 2]
  20. set des_dir [lindex \$argv 3]
  21. set timeout -1
  22. spawn scp -r \$src_file root@\$ip:\$des_dir
  23. expect {
  24. "yes/no"     { send "yes\r"; exp_continue }
  25. "password:"  { send "\$passwd\r" }
  26. }
  27. expect "100%"
  28. expect eof
  29. EOF
  30. ##Auto exec shell scripts
  31. if
  32.     [ "$1" == "" ];then
  33.     echo ========================================================
  34.     echo "Please insert your are command ,Example {/bin/sh  $0 /src  /des } ,waiting exit ........... "
  35.     sleep 2
  36.     exit 1
  37. fi
  38. for i in `awk '{print $1}'  passwd.txt`
  39. do
  40.       j=`awk -v I="$i" '{if(I==$1)print $2}' passwd.txt`
  41.       expect ./login.exp  $i  $j $1 $2
  42. done</font>
复制代码



懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表