shell script to scp multiple file to multiple destinations

 


#!/bin/bash

# Prompt the user for the name of the file to transfer using printf and read commands
printf "Enter the name of the file to transfer: "
read filename
# Prompt the user for the IP addresses to transfer the files to using printf and read commands
printf "Enter the IP addresses to transfer the file(s) to (separated by spaces): "
read -a ips
# Define the username to use for the SCP transfer
username="user"
# Loop through the array of IP addresses and transfer the file to each one
for ip in "${ips[@]}"
do
    # Use printf to display a message before transferring each file
    printf "Transferring %s to %s...\n" "$filename" "$ip"
   
    # Use scp to transfer the file to the current IP address
    scp "$filename" "${username}@${ip}:~/"
done
# Use printf to display a summary message when the transfers are complete
printf "Transferred %s to %d IP addresses.\n" "$filename" "${#ips[@]}"

Comments

Popular posts from this blog

Shell script to find out aliases and their expiration in cacerts

How to resolve port conflict in websphere