Execute command line and shell commands from PHP

PHP’s system() command will let you run command line and shell stuff. It probably requires proper permissions on your ISP configuration.

http://www.php.net/manual/en/function.system.php

$last_line = system(‘PATHTO_COMMAND’, $retval);

Why do I need this? For the life of me I can’t figure out how to run a simple shell script through cron.

I saw somewhere that the cron would be something like this but it does not work:

10 * * * `/bin/sh PATHTOSCRIPT`

Inspired by Drupal’s cron.php stuff that runs search indexing, I wrote a PHP script that will run my shell commands. Since the scripts can echo to standard out, the PHP command will print the debugging results to the web page. Now I can check the status of my script without logging in through SSH every time.

There is definitely a better way to do this. Let me know if you can think of something. If anyone knows how to run a shell script (/bin/sh) through cron via cPanel’s cron admin please let me know.