【发布时间】:2014-03-05 22:00:40
【问题描述】:
我在尝试使用 shell_exec() 函数通过 php 运行以下脚本时遇到问题。
#!/bin/bash
/usr/bin/sshpass -p 'password' /usr/bin/rsync -avzhe -O
"ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p port"
--exclude '*html' --include='R*' --exclude '*'
username@ipaddress:/location/ /location
当我在终端或通过 php shell_exec() 运行此脚本时,我收到以下错误:
Unexpected remote arg: username@IP:/location/
rsync error: syntax or usage error (code 1) at main.c(1201) [sender=3.0.6]
如果我从 rsync 部分删除“-O”,它在终端中可以正常工作,但通过 php 我得到以下错误:
rsync: failed to set times on "/destination_location/.": Operation not permitted (1)
rsync: mkstemp "/location/.file.pSnb11" failed: Permission denied (13)
rsync: mkstemp "/location/.file.hR7VUM" failed: Permission denied (13)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1505) [generator=
下面是php代码。
<?php
if (isset($_POST['button']))
{
shell_exec('/location/rsync.sh');
}
?>
<html>
<body>
<form method="post">
<p>
<button name="button">Run Script</button>
</p>
</form>
</body>
【问题讨论】:
-
提示:什么用户运行你的脚本?
-
由于终端运行时报错,与php无关
-
根用户在终端运行它。 @Dragon 如果您阅读了完整的帖子,您会注意到我说如果您从 rsync 中删除“-O”,它在终端中运行良好,但通过 php 运行时会出现更多错误。