Link to home
Start Free TrialLog in
Avatar of nighter33
nighter33

asked on

Problem passing file name with spaces to shell script

A part of my python script calls a shell script (Rsyncc.sh) and passes variables.

Problem is with var3 which is a file name. If it contains spaces, Rsyncc.sh doesn't get the entire string.

var3 = "/app/interface/exports/TEST5191 326150.txt"

My question is how to send var3 - imbedded spaces and all?

bashcall(var,var1,var2,var3):
irtn = os.system("./Rsyncc.sh %s %s %s %s " % (var,var1,var2,var3))



This is the code from rsyncc.sh. sfile accepts parameter #4, the file name(sfile).

#!/bin/bash

clear


# Variables below

remotehost=$1
rsyncmodule=$2
dest=$2
sfile=$4

rsync -avz -e "ssh -p 22 -i /home/testusr/.ssh/key1 " $sfile rsyncadmin@$remotehost:$dest
SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't know Python at all - could it be that those double quotes can/must be applied here, too ("var3")?

bashcall(var,var1,var2,"var3"):
irtn = os.system("./Rsyncc.sh %s %s %s %s " % (var,var1,var2,"var3"))

Or does the above keep Python from interpreting "var3" as a variable name? Sorry for the stupid suggestion then!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nighter33
nighter33

ASKER

Thanks for the suggestions but same error -only passes the first part of the file name up to the first space in both cases..
Did you make the changes I suggested to the bash code? They're required, regardless of what you're doing with the Python code!
My error. I made both changes and it works!
Thank you very much.
Response was very quick.
If you made both changes, why did you accept only one answer?
I agree - wmp and I gave half the answer each!
Sorry, new to this. Can I correct?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial