Does Python subprocess.check_call process rsync differently from bash?

Asked by Aaron Whitehouse on 2014-06-01

I put this here mainly because I spent ages trying to find the problem and it didn't make sense to me.

I had a script (edited here to just the key lines):
local_path = "/media/annex/Annex/archive/Backup/duply_backups/*"
remote_path = "/media/Beta/backup/Duply_Backups/"
subprocess.check_call(["rsync", "--delete", "-r", "-v", local_path, remote_path])

Which threw:
rsync: link_stat "/media/annex/Annex/archive/Backup/duply_backups/*" failed: No such file or directory (2)

Copying and pasting the command into the terminal:
rsync --delete -r -v /media/annex/Annex/archive/Backup/duply_backups/* /media/Beta/backup/Duply_Backups/
worked exactly as expected.

I ended up trying removing the * in the local path, giving:
local_path = "/media/annex/Annex/archive/Backup/duply_backups/"
and it now works as expected. I realise that this may be more proper, but I was surprised that the command worked differently in these two situations. Does anyone have an answer as to why?

Question information

English Edit question
Ubuntu python-defaults Edit question
No assignee Edit question
Last query:
Last reply:

This question was reopened

Manfred Hampl (m-hampl) said : #1

The root cause probably is the following:

Not providing a shell=... parameter to subprocess.check_call implies shell=false
This might cause the difference in behaviour, because in that case there is no file name expansion.

Apparently the system tries to find a file/directory named "/media/annex/Annex/archive/Backup/duply_backups/\*" that does not exist, instead of using the '*' as wild card.

see also

Can you help with this problem?

Provide an answer of your own, or ask Aaron Whitehouse for more information if necessary.

To post a message you must log in.