#!/bin/bash # ==================================================================================== # # Title: # scpbak.sh # # Description: # A simple shell script to transfer files to a remote server, # followed by adding a suffix to transfered files to mark it as complete. # # # Author: # Elias Hussary # # Last Update: # 2018-09-14 # # ==================================================================================== # assign args input_dir=$1 input_glob=$2 remote_path=$3 file_suffix=$4 # print args echo " $(date) input_dir=$input_dir input_glob=$input_glob remote_path=$remote_path file_suffix=$file_suffix " # if last arg is null, throw err if [ -z $4 ] then >&2 echo -e "\nERROR: Missing argument; you must input all arguments." exit 1 fi echo -e "\nTransferring files...\n" # do scp transfer and save return code scp $input_dir$input_glob $remote_path rc=$? if [ $rc -eq 0 ] then # if return code = 0 (success) then rename files echo -e "\nRenaming files...\n" for file in $input_dir$input_glob do mv $file $file$file_suffix echo "$file -> $file$file_suffix" done echo -e '\nSUCCESS: Operation completed' exit 0 else # if return code != 0 (error) then exit >&2 echo -e '\nERROR: Transfer failed' exit 1 fi