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

  • 相关阅读:
    【C++基础】重载,覆盖,隐藏
    【Lintcode】003.Digit Counts
    【C++ Primer 5th】Chapter 15
    【Lintcode】120.Word Ladder
    牛客网上的题
    二叉树中和为某个值得路径
    数据库
    二叉搜索树的后序遍历序列
    从上往下打印二叉树
    二叉树的镜像
  • 原文地址:https://www.cnblogs.com/Malphite/p/10313271.html
Copyright © 2011-2022 走看看