bash scp cmd to copy directory wise data from one server to anohter server
- User
bash scp cmd to copy directory wise data from one server to anohter server
- Assistant
The
scpcommand 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_directoryMake sure to replace
/path/to/source_directorywith the actual directory path on the source server,userwith the username on the destination server,destination_serverwith the IP address or hostname of the destination server, and/path/to/destination_directorywith the actual directory path on the destination server.The
-rflag is used to recursively copy the directory and its contents. - User
bash script with scp command to move the file in day wise directory to destination directory daywise in different server
- Assistant
Sure! Here's a bash script that uses the
scpcommand 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." fiMake sure to replace
source_server,source_username,source_directory,destination_server,destination_username, anddestination_directorywith 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.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.