ubuntu 自定义命令,在服务器之间传文件

1. 搞个腾讯云服务器

伟大的XHJ帮我搞的,一年只要几百块钱,学生号。硬盘容量 60G。

2. ubuntu 下编辑一个自定义命令: tpull

因为是疼讯,所以 t 打头,pull 表示从云端拷贝文件下来。
自定义命令对应的可执行文件内容如下。

#!/bin/bash

file=$1

sshpass -p xxx scp -r ubuntu@1.xx:~/$file .

3. ubuntu 下编辑一个自定义命令:tpush

#!/bin/bash

file=$1
destination=$2

echo $destination

if [ ${destination:-1} == 1  ]
then
        echo "passing $file to tencent"
        sshpass -p xx scp -r $file ubuntu@xx:~/
elif [ $destination == swagger ]
then
        echo "passing $file to swagger"
        sshpass -p xx scp -P1234 -r $file luyi@x.x.x.x:~/Downloads/
fi

其中,

  • ${destination:-1} 表示如果变量 destination 未赋值,则返回 1。所以默认把文件传上云端,给两个参数的话也可以传到其他电脑。

posted on 2022-07-27 11:36  luyi07  阅读(261)  评论(0编辑  收藏  举报

导航