zoukankan      html  css  js  c++  java
  • scp 脚本

     1 #!/bin/bash
     2 
     3 ty=$1
     4 local_dir=$2
     5 remote_ip=$3
     6 remote_dir=$4
     7 
     8 showUsage() {
     9         echo -e "33[31m ty local_dir remote_ip remote_dir 33[0m"
    10         echo -e "33[32m ty = l(local to remote); ty = r(remote to local) 33[0m"
    11         echo -e "33[32m local_dir = local file or local dir 33[0m"
    12         echo -e "33[32m remote_dir = remote file or remote dir 33[0m"
    13 }
    14 
    15 #Copy the local file to the remote server
    16 l_to_r() {
    17 expect -c "
    18         spawn scp -r ${local_dir} 1234@${remote_ip}:${remote_dir}
    19         expect {
    20         "*password" {set timeout 300; send "abcd
    ";}
    21         }
    22 
    23 expect eof"
    24 }
    25 
    26 #Copy the remote file to the local server
    27 r_to_l() {
    28 expect -c "
    29         spawn sudo scp -r 1234@${remote_ip}:${remote_dir} ${local_dir}
    30         expect {
    31         "*password" {set timeout 300; send "abcd
    ";}
    32         }
    33 
    34 expect eof"
    35 }
    36 
    37 case $1 in
    38         "l")
    39                 l_to_r
    40         ;;
    41         "r")
    42                 r_to_l
    43         ;;
    44         *)
    45                 showUsage
    46         ;;
    47 esac

    使用方法:

      1、1234替换为ssh account

      2、abcd替换为ssh passwd

      示例:./scp.sh r ~/MOUNT 192.168.1.110/home/123.cpp

  • 相关阅读:
    jqurey技术总结
    ie浏览器兼容问题小结
    FIS的合并压缩技术
    对js中数组的一些总结
    浅谈如何面向对象进行封装
    13th week blog
    12th week blog
    11th week blog
    10th week blog
    9th Week blog
  • 原文地址:https://www.cnblogs.com/Malphite/p/10313271.html
Copyright © 2011-2022 走看看