当前位置: 动力学知识库 > 问答 > 编程问答 >

linux - Copying files to other virtual machines using UNIX BASH

问题描述:

I need help with copying files from directory if they are not empty to other virtual machines using UNIX BASH (kinda new with it).

e.g. VM ip 10.123.123.1 ; file name " q.txt". How do I make it ?

网友答案:

Use following script to check if the file is not empty and copy (scp) to your destination

_file="$1"
[ $# -eq 0 ] && { echo "Usage: $0 filename"; exit 1; }
[ ! -f "$_file" ] && { echo "Error: $0 file not found."; exit 2; }

if [ -s "$_file" ]
then
    echo "$_file has some data."
    scp $_file <USER>@10.123.123.1:<YOUR_DESTINATION_PATH>
else
    echo "$_file is empty."
fi

NOTE: You need to set the user name and path where you want to store your file on your destination target

分享给朋友:
您可能感兴趣的文章:
随机阅读: