duanhaodi4809 2011-11-24 12:39
浏览 77
已采纳

如何用php一个接一个地执行.sh文件

I need to run a series of six .sh files on the server.

An example of one of the .sh files:

wget ftp://xxxxxx:xxxxxx@ftp.interhome.com/accommodation.xml.zip
unzip accommodation.xml.zip
php accommodation.php
rm -rf accommodation.xml.zip
rm -rf accommodation.xml

I tried running the following from a php file:

echo shell_exec('sh accomodation.sh');

Which was stupid because the file appears to execute repeatedly and I think I've just taken down the server. Whoops.

I've inherited this site and have never used .sh files before. I'm also a php novice.

How would I go about running the files only once and then running the next?

Many thanks

  • 写回答

1条回答 默认 最新

  • dongsi3826 2011-11-24 13:03
    关注

    you can do all this from within PHP, you do not need any shell-script.

    /* get the file via ftp */
    // connect to server
    $ftp = ftp_connect('ftp.interhome.com');
    // login
    $login = ftp_login($ftp,"username","password");
    // download file to tmp.zip
    $file = ftp_get($ftp, 'tmp.zip', 'accommodation.xml.zip', FTP_BINARY);
    // disconnect from server
    ftp_close($ftp);
    
    /* unzip the file */
    // new zip-instance
    $zip = new ZipArchive;
    // open downloaded file
    $res = $zip->open(’tmp.zip’);
    // check if file is readable
    if ($res === TRUE) {
      // extract to current directory
      $zip->extractTo(’./’);
      // close zip-file
      $zip->close();
    }
    
    /* your code from accommodation.php goes here */
    
    // delete files
    unlink('tmp.zip');
    unlink('accommodation.xml');
    

    voila

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?