How to delete source files, copied using scp?

From FVue

Jump to: navigation, search

Contents

Problem

I want to copy Apache log files from a remote machine and delete them afterwards – if copying was successful.

Solution

Ssh to server with rm command:

scp server:~/log/yyyymmdd.gz client && ssh server rm ~/log/yyyymmdd.gz

Workaround

After having copied the source file, copy an empty source file back to the original source file. This frees space, but leaves a filename on the server though.

In bash-pseudocode

    # Copying file from server to client is successful?
if scp server:~/log/yyyymmdd.gz client; then
    # Yes, copying file form server to client is successful;
        # Create empty file
    touch empty_file
        # Copy empty file to server source file
    scp empty_file server:~/log/yyyymmdd.gz
fi

Journal

Someone submitted (and withdrew) an scp patch to delete source files after copy.

Perhaps I could schedule the copy on the client.

Personal tools