0

I am creating a simple web page that will allow the user to select an option on a basic php page, click submit, and then the backend PHP should execute a bash script, that will execute some AppleScript.

I can run the bash script from Terminal and it runs the Applescript file fine using osascript but when I try executing the bash script from php, it will run echo commands, but will not execute the osascript line. I imagine this is a permissions issue, but I changed everything to full privilege using chmod 777 (admittedly not the best idea, but that is besides the point)

Is there something I am missing? It is weird that it seems to skip completely over the osascript line. Any suggestions? Thanks in advance!

CODE:

PHP

<?php
if (isset($_POST['submit'])) {
    $username =  $_POST['username'];
    if (strcasecmp($username, 'user1') == 0) {
        echo 'test1';
    } else if (strcasecmp($username, 'user2') == 0) {
        echo 'test2';
    } else if (strcasecmp($username, 'user3') == 0) {
        echo 'test3';
    } else if (strcasecmp($username, 'user4') == 0) {
        shell_exec('cd ~/Sites;./a.out');
    }
}
?>

BASH

#!/bin/bash
echo "test String"
cd /Users/Zimmerman/Library/Scripts
osascript /Users/Zimmerman/Library/Scripts/testscript.scpt
echo "test String"
MZimmerman6
  • 8,445
  • 10
  • 40
  • 70

1 Answers1

0

Your apache $PATH variable is probably not looking within /usr/bin/. If you echo shell_exec('which osascript'); within a PHP file, you might not see anything, but you will see results on terminal.

You can add paths to your webservers $PATH variable or you could perhaps try using the full path to the executable /usr/bin/osascript on your scripts.

dakdad
  • 2,947
  • 2
  • 22
  • 21
  • You're right I do not see it when using `shell_exec('which osascript')` I am not that good with webserver/apache stuff, how would I go about doing this simply. Thanks! – MZimmerman6 Oct 22 '12 at 18:49
  • On your shell script, did you try replacing `osascript` with `/usr/bin/osascript` so it has the full path? – dakdad Oct 22 '12 at 18:57
  • Perhaps this can help http://stackoverflow.com/questions/2837697/how-do-i-add-paths-to-the-apache-path-variable – dakdad Oct 22 '12 at 19:08