exec 未找到文件
我在使用 exec php 函数时遇到问题。 当我这样做时:
ls -al /dev/sdf1
这没有找到存档(ls:无法访问/dev/sdf1:没有这样的文件或目录),但是如果我运行此命令,在控制台中会显示信息。 我能做些什么? 即使以 root 身份运行 php 脚本也会发生这种情况!
$mountcommand = "ls -al /dev/$unit 2>&1";
exec("$mountcommand", &$mountoutput, &$mountresult);
print_r($mountoutput);
echo "\n$mountcommand\n\n";
这是一个分叉的过程
I'm having problems with the exec php function.
When I do:
ls -al /dev/sdf1
This doesn't found the archive (ls: cannot access /dev/sdf1: No such file or directory), but if I run this command, in console that show me the information.
What can I do?
That happen even running the php script as a root!!
$mountcommand = "ls -al /dev/$unit 2>&1";
exec("$mountcommand", &$mountoutput, &$mountresult);
print_r($mountoutput);
echo "\n$mountcommand\n\n";
This is in a forked process
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对我有用。
磁盘:
使用 hde:
使用 PHP:
脚本:
更新
它也适用于
ls -al
。请出示你的脚本。
更新 2
按照 ircmaxell 的 chroot 建议:假设 /dev(如 PHP 进程中所示)是真实的 chroot 传真的特殊版本。假设 /dev/sdf1 是可移动设备。当插入sdf1(媒体)时系统会自动在真实的/dev中创建设备;但chroot版本没有更新。因此,要检测这种情况,请从 PHP 和命令行中查找 /dev 之间的差异。
一项测试是 /dev 上的
ls -id
(来自 PHP 和命令行)。这会打印 /dev 的 inode。 inode 编号是否不匹配?/dev/sdf1 可以删除吗?装了吗?如果已安装; PHP 进程是否从 PHP 中看到已安装的文件系统:
ls $mount_point
。Stack Overflow 上和其他地方还列出了其他 chroot 测试;但我还没有发现很多好的方法:如果 chroot 正确完成,则很难检测到。
更新 3
这可能是正在发生的情况:设备 (/dev/sdf1) 在创建后需要一段时间才能出现;因此有必要在创建设备和尝试挂载之间暂停:
之前:设备已创建;但它不在那里...
之后:添加了 1 秒暂停,并且设备 (sdg) 可用...
带有暂停的 PHP ...
/etc/sudoers 是配置与上一个关于从 PHP 挂载失败的问题中报告的相同。
因此,在 iscsiadm 创建设备后添加一两秒的 sleep() 。睡眠可以在 PHP 中完成,而不是在 shell 的 exec() 中完成。
Works for me.
The disks:
Using hde:
Using PHP:
The script:
Update
It also works with
ls -al
.Please show your script.
Update 2
Along the lines of the chroot suggestion by ircmaxell: Supposing that /dev, as seen in the PHP process, was a special chroot facsimile of the real one. And supposing that /dev/sdf1 is a removable device. The when sdf1(the media) is inserted the system automatically creates the device in the real /dev; but the chroot version isn't updated. So, to detect this situation look for differences between /dev as seen from PHP and from the commandline.
One test is
ls -id
on /dev(from PHP and the commandline). This prints the inode of /dev. Is there a mismatch in inode numbers?Is /dev/sdf1 removable? Is it mounted? If it is mounted; does the PHP process see the mounted filesystem:
ls $mount_point
from PHP it.There are other chroot tests listed on Stack Overflow and elsewhere; but I haven found many good ones: If a chroot is done correctly, it is hard to detect.
Update 3
This may be what is happening: The device (/dev/sdf1) takes a while to appear after it is created; so it is necessary to pause between creating the device and attempting to mount it:
Before: The device is created; but it isn't there...
After: Added a 1-second pause, and the device (sdg) is available...
The PHP with the pause ...
The /etc/sudoers is configured the same as reported in the previous question about mount failing from PHP.
So add a second or two of sleep() after iscsiadm creates the device. The sleep can be done in PHP instead of in the exec() of the shell.
我通过在这段代码和给我“单位”的代码之间休眠来修复它
I fix it with a sleep between this code and the code that gave me the "unit"