문제 설명
bash의 rsync가 php 생성 ‑‑exclude‑from 파일을 구문 분석하지 않음 (rsync in bash not parsing php‑generated ‑‑exclude‑from file)
My rsync bash script isn't parsing my ‑‑exclude‑from file that's generated via php, but it will if I manually create (as root) the same exact file locally. I've got a web interface on a Xubuntu 12.10 system that writes rsync ‑‑exclude‑from files locally and then pushes them via rcp to our (CentOS 6) backup boxes that run the rsync script. (Please spare finger wagging about rcp... I know‑‑don't have a choice in this case.)
Webpage writes file:
PHP:
file_put_contents($exclfile, $write_ex_val);
then pushes to the backup box from a local bash script on the webserver with:
Bash:
rcp ‑p /path/to/file/${servername}_${backupsource}.excl ${server}:/destination/path
I've compared the permissions and ownership of the hand‑created file (that works) with the same file that's php/rcp'd (that doesn't), and they're both the same:
Bash:
stat ‑c '%a' server_backupsource_byhand.excl
644
stat ‑c '%a' server_backupsource_byphp.excl
644
ls ‑l server_backupsource_byhand.excl
‑rw‑r‑‑r‑‑ 1 root root 6 May 11 05:57 server_backupsource_byhand.excl
ls ‑l server_backupsource_byphp.excl
‑rw‑r‑‑r‑‑ 1 root root 6 May 11 05:58 server_backupsource_byphp.excl
In case it's relevant, here's my rsync line:
BASH:
rsync ‑vpaz ‑v ‑‑exclude‑from=${exclfile} /mnt/${smbdir} /backup
I suspect php might be writing the file in a different format (e.g. UTF8 instead of ANSI), but I can't figure out how to test this, and have limited knowledge here.
Does anyone have any suggestions on how to get the php/rcp generated file to parse?
참조 솔루션
방법 1:
Using diff and file I found out that the php‑written version wasn't writing the newline. In my variable definition I was using a "." as "$write_ex_val ." Removing this "." let php write the new lines. I also removed the space between the variable and "\n", although I'm not sure if this contributed to the solution. I'd upvote the comment, Earl, but I don't think I have enough rep. Thanks again.