一般PHP命令行的编写
2011-06-19 13:41
281 查看
#!/usr/local/bin/php
<?php
error_reporting (0);
if (count($argv) <= 1 || $argv[1] == "-h") {
die ("No file or directory to sync./nUsage: synchronize file1[directory1] file2[directory2] .../n/n");
}
//$hosts = unserialize (file_get_contents("/bin/hosts"));
$hosts = file("/bin/hosts.line");
//$path = get_pwd();
$path = getcwd();
for ($i = 1; $i < count($argv); $i ++) {
if (strstr($argv[$i], "/") != $argv[$i]) $src = $path."/".$argv[$i];
else $src = $argv[$i];
if ($_SERVER["LOGNAME"] != 'root' || substr ($src, 0, 30) !== "/usr/local/apache2/htdocs/")
{
echo $src." not allowed./n";
continue;
}
$tar = dirname($src)."/";
if (is_dir($src)) {
foreach ($hosts as $h){
$h = trim ($h);
$cmd = "sudo /usr/bin/scp -r ".$src." test@".$h.":".$tar;
ex ($cmd);
}
} elseif (is_file($src)) {
foreach ($hosts as $h){
$h = trim ($h);
$cmd = "sudo /usr/bin/scp ".$src." test@".$h.":".$tar;
ex ($cmd);
}
} else {
echo "ignore ".$src." (does not exists?)/n";
}
}
function get_pwd () {
return $_SERVER['PWD'];
}
function ex ($cmd) {
echo substr($cmd, 14)."->executing, please wait...";
system ($cmd);
echo "ok!/n";
}
?>
<?php
error_reporting (0);
if (count($argv) <= 1 || $argv[1] == "-h") {
die ("No file or directory to sync./nUsage: synchronize file1[directory1] file2[directory2] .../n/n");
}
//$hosts = unserialize (file_get_contents("/bin/hosts"));
$hosts = file("/bin/hosts.line");
//$path = get_pwd();
$path = getcwd();
for ($i = 1; $i < count($argv); $i ++) {
if (strstr($argv[$i], "/") != $argv[$i]) $src = $path."/".$argv[$i];
else $src = $argv[$i];
if ($_SERVER["LOGNAME"] != 'root' || substr ($src, 0, 30) !== "/usr/local/apache2/htdocs/")
{
echo $src." not allowed./n";
continue;
}
$tar = dirname($src)."/";
if (is_dir($src)) {
foreach ($hosts as $h){
$h = trim ($h);
$cmd = "sudo /usr/bin/scp -r ".$src." test@".$h.":".$tar;
ex ($cmd);
}
} elseif (is_file($src)) {
foreach ($hosts as $h){
$h = trim ($h);
$cmd = "sudo /usr/bin/scp ".$src." test@".$h.":".$tar;
ex ($cmd);
}
} else {
echo "ignore ".$src." (does not exists?)/n";
}
}
function get_pwd () {
return $_SERVER['PWD'];
}
function ex ($cmd) {
echo substr($cmd, 14)."->executing, please wait...";
system ($cmd);
echo "ok!/n";
}
?>
相关文章推荐
- php命令行程序编写范例
- 编写php扩展一般步骤
- php smarty程序编写一般步骤
- PHP扩展编写与编译
- memcached的命令行、导出和导入、php连接、memcached中存储sessions
- php中soap使用,SoapServer服务端编写,SoapClient客户端编写
- 在 Linux 命令行中使用和执行 PHP 代码(二):12 个 PHP 交互性 shell 的用法
- 用PHP编写Hadoop的MapReduce程序
- 编写网络方案一般遵循如下结构提纲
- PHP 读取和编写 XML DOM
- 简单php文件编写语法
- 命令行方式运行php脚本
- 个人网站留言页面(前端jQuery编写、后台php读写MySQL)
- PHP Yii 命令行程序以及定时任务详解
- 在php中调用接口以及编写接口
- PHP 的命令行模式
- 在编写PHP时遇到的一些小问题
- [PHP] 命令行执行整合pathinfo模拟定时任务
- PHP100-6 编写一个函数解析多重嵌套数组的所有元素
- 编写自己的php扩展函数(一)