【发布时间】:2013-02-06 21:35:46
【问题描述】:
我想运行一个包含 IP 数组的 PHP,并从每个 IP 中删除一个特定文件。
类似这样的:
foreach($servers as $ip){
shell_exec("sh /my/dir/delete.sh ".$ip." ".$file);
}
在 delete.sh 文件中我会有这样的东西
ssh user@$1 'rm /my/dir/filespath/$2 '
所有服务器都有相同的路径和文件,还有用户名和密码 请问有什么建议吗?
编辑:
执行 sh 文件的 PHP 文件位于安全管理员页面中,IP 为本地 IP(192.168.1.25、26、27)
如果我想从路径中删除所有文件,我会这样做(就像我现在正在做的那样)
ssh user@192.168.1.25 '/usr/bin/find /my/dir/filespath/* -type d -exec /bin/rm -fr {} \;'
ssh user@192.168.1.26 '/usr/bin/find /my/dir/filespath/* -type d -exec /bin/rm -fr {} \;'
ssh user@192.168.1.27 '/usr/bin/find /my/dir/filespath/* -type d -exec /bin/rm -fr {} \;'
但我只想删除一个特定文件,例如:/my/dir/filespath/other/folder/file.txt
由于我将添加更多服务器或更改它们的 IP,我需要它们是可变的 [现在这不是强制性的]
【问题讨论】:
-
目前的解决方案到底有什么问题?
-
也许应该是
/bin/sh /my/dir/delete.sh ...而不仅仅是 sh -
您确定没有更好的方法吗?在安全方面,您的处境并不好。
-
好吧.. 我需要在安全页面中从 PHP 生成 URL 并将其传递给 bash 文件.. 还有哪些建议?