Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

bash scp cmd to copy directory wise data from one server to anohter server

  1. User

    bash scp cmd to copy directory wise data from one server to anohter server

  2. Assistant

    The scp command can be used to copy directory contents from one server to another using the following syntax:

    scp -r [source_directory] [user]@[destination_server]:[destination_directory]
    

    Here's an example of how to use it:

    scp -r /path/to/source_directory user@destination_server:/path/to/destination_directory
    

    Make sure to replace /path/to/source_directory with the actual directory path on the source server, user with the username on the destination server, destination_server with the IP address or hostname of the destination server, and /path/to/destination_directory with the actual directory path on the destination server.

    The -r flag is used to recursively copy the directory and its contents.

  3. User

    bash script with scp command to move the file in day wise directory to destination directory daywise in different server

  4. Assistant

    Sure! Here's a bash script that uses the scp command to move files from day-wise directories on the source server to day-wise directories on the destination server:

    #!/bin/bash
    
    source_server="source_server"
    source_username="source_username"
    source_directory="/path/to/source_directory"
    destination_server="destination_server"
    destination_username="destination_username"
    destination_directory="/path/to/destination_directory"
    
    # Get the current date in the format YYYY-MM-DD
    current_date=$(date "+%Y-%m-%d")
    
    # Create the source and destination directory paths for the current date
    source_path="$source_directory/$current_date"
    destination_path="$destination_directory/$current_date"
    
    # Check if the source directory for the current date exists
    ssh $source_username@$source_server "if [ -d $source_path ]; then echo 'exist'; fi" > /dev/null
    
    if [[ $? -eq 0 ]]; then
        # Create the destination directory for the current date on the destination server
        ssh $destination_username@$destination_server "mkdir -p $destination_path"
        
        # Copy the files from the source directory to the destination directory
        scp -r $source_username@$source_server:$source_path/* $destination_username@$destination_server:$destination_path
        
        if [[ $? -eq 0 ]]; then
            echo "Files copied successfully."
        else
            echo "Failed to copy files."
        fi
    else
        echo "Source directory not found for the current date."
    fi
    

    Make sure to replace source_server, source_username, source_directory, destination_server, destination_username, and destination_directory with the actual server details and directory paths.

    The script retrieves the current date and creates the source and destination directory paths using that date. Then it checks if the source directory exists for the current date on the source server. If it exists, it creates the destination directory for the current date on the destination server (if it doesn't already exist) and performs the copy operation using scp -r. Finally, the script provides appropriate status messages.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.