This question already has an answer here:

I have a script that copy files to another server. I don't want to overwrite any files so I have to use rsync.

I can use rsync without any problem when I run at command line. But when I use it in script, rsync does not work. It gives an error and I even could not find that error at Google.

Here is error:

rsync: Failed to exec ssh: Not a directory (20)
rsync error: error in IPC code (code 14) at pipe.c(84) [sender=3.0.9]
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in IPC code (code 14) at io.c(605) [sender=3.0.9]

I would like to point that error is not No such file or directory(2)

Error is: Not a directory(20)

Here is script:

DAY=$(/usr/bin/date +'%Y-%m-%d')
/usr/bin/rsync -avh $PATH postgres@REMOTE_IP:/Backup/xlog_backup/$DAY/.

I am using like this

sh ~postgres/archive.sh /srv/postgresql/data/pg_xlog/000000010000003E00000025 000000010000003E00000025

Here is ls output:

postgres@MY_SERVER:~$ls -l /srv/postgresql/data/pg_xlog/000000010000003E00000025
-rw-------. 1 postgres postgres 16777216 May 25 10:41 /srv/postgresql/data/pg_xlog/000000010000003E00000025

Server: CentOS Linux release 7.2.1511 (Core)

Rsync: rsync version 3.0.9 protocol version 30

postgres@MY_SERVER:~$rpm -qa | grep openssh





Could you help me to solve the problem?

marked as duplicate by Kusalananda, phk, Satō Katsura, Archemar, roaima May 26 '17 at 9:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Don't use $PATH as a variable in your scripts!!!

It will override your, eh, $PATH.

An example:

echo $PATH   

If I assign something else to $PATH, what happens?

maulinglawns@debian-HP:~$ PATH=foo
maulinglawns@debian-HP:~$ echo $PATH
maulinglawns@debian-HP:~$ ls
bash: ls: command not found

As a general recommendation, I would suggest to avoid using UPPERCASE only entirely when assigning variables in your scripts. It is better that they are left as reserved for the shell's environment variables.

  • Thank you very much. I missed that PATH can be overwritted. Problem is gone now. – Yavuz Selim May 25 '17 at 8:19
  • @YavuzSelim No problem. I have made the same mistake (once) in the past. That's how we learn ;-) – maulinglawns May 25 '17 at 8:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.