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


How to execute .sh files one after another with php

我需要在服务器上运行一系列六个.sh文件。

.sh文件的一个示例:

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

我尝试从php文件中运行以下命令:

echo shell_exec('sh accomodation.sh');

这是愚蠢的,因为该文件似乎反复执行,我认为我刚刚关闭了服务器。哎呀。

我继承了这个网站,以前从未使用过。sh文件。我也是一个php新手。

我该如何只运行一次文件然后再运行下一次?

多谢

您可以在PHP中完成所有这些操作,不需要任何shell脚本。

/* 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');