使用php调用shell脚本同步文件

原创
2016-07-28 08:27:49 1004浏览

当你在上传文件的时候需要同步到另外机器的时候,可以执行shell脚本实现文件同步

#! /bin/bash
a=$1
b=$2
ip=$3
port=$4
passwd=$5
/bin/rpm -qa|/bin/grep -q expect
if [ $? -ne0 ];thenecho"please install expect"exitfiif [ $#-ne5 ];thenecho"must 5 parameter,1:source file,2:object file,3:object ip 4:object port,5:passwd"exitfi
expect -c "
  spawn scp -P $port$a root@$ip:$b
  expect {
    \"*assword\" {set timeout 300; send \"$passwd\r\";}
    \"yes/no\" {send \"yes\r\"; exp_continue;}
  }
  expect eof"

运行脚本需要安装expect,直接yum安装即可
expect脚本是一种建立在tcl基础上的脚本语言,曝光率不高,却堪称shell脚本的好基友。expect脚本为交互而生,被设计为专门针对交互式程序的工具,常与对telnet、ftp、fsck、rlogin、tip、scp等配合使用
如果是从win上编辑过的脚本在linux下出现no such file or directory,可在linux下vi脚本执行

:sef ff=unix

在php执行shell脚本时,记得要写绝对路径

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了 使用php调用shell脚本同步文件,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。