georgeocrawford
Technical User
Hi,
I'm getting in a bit of a muddle here. I have a PHP script which makes a couple of shell commands, and collects the output.
One of the shell commands is to test if a given file is a Mac OS X alias. If it is, the shell returns the path that the alias points to. To do this, it uses an AppleScript subroutine.
The problem is that the Applescript uses some property (don't understand at all - something to do with WindowManager) which means it must be run under the same username as is currently logged in (i.e. me). However, Apache was set to run as so it couldn't run the script.
I changed httpd.conf to run Apache as me (myusername:admin), and the script worked on my test computer, running OS X 10.3. It also worked OK on the server, which runs OS X Server 10.2.
There is another problem. Another part of the script uses a shell command to search through a directory for certain files and record the results in a text file. On my test machine, this works fine. However, the server, which I set to run Apache as theadminusername:admin, can't perform the scan. It just writes a blank text file.
If it's important, the first shell call is
which uses the aliascheck command I have put at /bin/aliascheck:
The second shell call is this:
(don't worry about the variables in here, $escaped_root is the path to the root folder for the search, $double_escaped_root is $escaped_root with all / changed to \/ for perl, and $escaped_data_folder is the path to the folder where I store the text file)
Can someone suggest why this doesn't work on the server? If I type the command directly into the terminal, it works fine, so it's obviously a problem with the user Apache runs as.
Which user should I run Apache as to make both shell commands work?
______________________
George
I'm getting in a bit of a muddle here. I have a PHP script which makes a couple of shell commands, and collects the output.
One of the shell commands is to test if a given file is a Mac OS X alias. If it is, the shell returns the path that the alias points to. To do this, it uses an AppleScript subroutine.
The problem is that the Applescript uses some property (don't understand at all - something to do with WindowManager) which means it must be run under the same username as is currently logged in (i.e. me). However, Apache was set to run as so it couldn't run the script.
I changed httpd.conf to run Apache as me (myusername:admin), and the script worked on my test computer, running OS X 10.3. It also worked OK on the server, which runs OS X Server 10.2.
There is another problem. Another part of the script uses a shell command to search through a directory for certain files and record the results in a text file. On my test machine, this works fine. However, the server, which I set to run Apache as theadminusername:admin, can't perform the scan. It just writes a blank text file.
If it's important, the first shell call is
Code:
$alias_path = shell_exec("aliascheck $escaped_path");
Code:
#!/bin/sh
if [ $# -eq 0 ]; then
echo "Usage: aliascheck file1 file2 file3..."
echo " where alias1, alias2, etc are files."
echo " Each file will be tested to see if it is an alias."
fi
while [ $# -gt 0 ]; do
if [ -f "$1" -a ! -L "$1" ]; then
item_name=`basename "$1"`
item_parent=`dirname "$1"`
# Next two rows should be entered as one row #
item_parent="`cd \"${item_parent}\" 2>/dev/null && pwd || echo \"${item_parent}\"`"
item_path="${item_parent}/${item_name}"
linksource=`osascript<<EOS
tell app "Finder"
set theItem to (POSIX file "${item_path}") as alias
if the kind of theItem is "alias" then
get the posix path of (original item of theItem as text)
end if
end tell
EOS`
if [ $? -eq 0 ]; then
if [ ! -z "$linksource" ]; then
echo "${linksource}"
fi
fi
shift
fi
done
The second shell call is this:
Code:
shell_exec('find ' . $escaped_root . " \! -name '.*' -print | perl -p -e 's/" . $double_escaped_root . "\///g; ' | perl -p -e 's/" . $double_escaped_root . "\n//g; ' > " . $escaped_data_folder . 'old.txt');
(don't worry about the variables in here, $escaped_root is the path to the root folder for the search, $double_escaped_root is $escaped_root with all / changed to \/ for perl, and $escaped_data_folder is the path to the folder where I store the text file)
Can someone suggest why this doesn't work on the server? If I type the command directly into the terminal, it works fine, so it's obviously a problem with the user Apache runs as.
Which user should I run Apache as to make both shell commands work?
______________________
George