bAd bOy
bAd bOy

Reputation: 33

rsync: failed to connect to 1.2.3.4\#015: Connection refused

I wanted to create a simple bash script to read IPs from a text file and run the following command to discover rsync service enabled IPs:

 rsync -av 1.2.3.4:: .

This is what I have done so far:

#!/bin/bash
filename="$1"
while read -r line
do
   name="$line"
   echo "Target: $name"
   rsync -av $name:: .
done < "$filename"

It does not seem to be working. Both the above scripts gave the following error:

rsync: failed to connect to 1.2.3.4\#015: Connection refused (111)
rsync error: error in socket IO (code 10) at clientserver.c(122) [Receiver=3.0.7]

Upvotes: 0

Views: 1198

Answers (1)

Cyrus
Cyrus

Reputation: 88959

I suggest first to remove carriage returns:

dos2unix "$filename"

or use:

dos2unix < "$filename" | while read -r line
do
   ...
done

Upvotes: 2

Related Questions