關於 PHP, Linux, Open Source 及個人生活記載的網誌。
RSS icon
  • 用 PHP 重寫現有 Shell Script

    Posted on February 6th, 2006 Sam Tang 1 comment

    PHP Shell以前寫的 Shell Script 一般用 sh 或 perl 來做,今天有空在家,決定將現時使用的幾個 shell script 用 PHP 重寫。

    改用 PHP 的原因是連接 MySQL 時很方便,以及內建有很多函式可以使用。但有一個錯誤我以前己經遇過,想不到今天一時忘記了又多犯一次,就是用 PHP 執行系統指令時,當人手處理時沒有問題 (例如 /usr/local/php/bin/php -q phpshell.php),但如果放到 crontab 執行就失敗。

    將 PHP 放入 crontab 自動執行,如需要執行系統指令,需要用上絕對路徑,例如:

    shell_exec(“uptime”);

    如果手動執行沒有問題,但放到 crontab 時,需要改成:

    shell_exec(“/usr/bin/uptime”);


     

    One response to “用 PHP 重寫現有 Shell Script”

    1. 試試看,也許有用–

    Leave a reply

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word