LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Shell script won't run from apache2 server (http://www.linuxquestions.org/questions/linux-server-73/shell-script-wont-run-from-apache2-server-879772/)

jackonapsp 05-10-2011 01:47 AM

Shell script won't run from apache2 server
 
Hi i was just wondering why apache2 won't run my shell script i made.
So in detail this is what i want it to do. I have a apache2 web-server running on my mac and i found some shell commands that control itunes so i wrote a shell script that basically pause's itunes. Now i have put the shell script in the cgi executable folder. and the link for the webpage is http://10.10.0.110/cgi-bin/itunes.sh but when i goto the page in my browser it just keeps loading. I have run other scripts and they work and i don't think you need root access. Please help!

Any help would be much appreciated.

baltho 05-10-2011 04:21 AM

If it was me, I'd write some debug code in there.

echo "starting script" >>some_file_apache_can_write_to

at the beginning, then the same before every line, find out what's causing the problem, then take it from there.
You shouldn't need root access, but apache is probably running as a different user to yourself, which could cause permission problems. (Hence the "some_file_apache_can_write_to" - the script will be running as the apache user).
Hope this helps: am a Ubuntu man myself, not mac, so just educated guesses...

lrtward 05-10-2011 07:34 AM

You can also run the script as follows:
Code:

cd /cgi-bin
sh -x itunes.sh

That will show you a lot of the steps as they are executed.

jackonapsp 05-11-2011 02:47 AM

Cannot cd into the specified directory
 
Ok so i did what you said and put "echo starting script > logs.txt" in the script and it stops at cd /library/webserver
why won't it cd into that directory could i just put the script in the root / would it work then?

#!/bin/bash
echo "Content-type: text/html"
echo ""
cd /library/webserver
echo starting script > logs.txt
./itunes.sh pause

lrtward 05-19-2011 01:02 PM

You say "I did what you said" but you didn't, really.

You need quotes around "starting script" so that the string "starting script" will be output to the logs.txt file.
You also need to put an echo statement between EVERY line of your script so you can tell how far you get.
You also need to use > for the first echo (so it will create the log file anew) and >> for each subsequent echo (so it will append to the new log file and not overwrite it).
Code:

#!/bin/bash
echo "starting script  logs.txt
echo "Content-type: text/html"
echo "after content-type" >> logs.txt
echo ""
echo "before cd to library/webserver" >> logs.txt
cd /library/webserver
echo "after cd to library/webserver" >> logs.txt
./itunes.sh pause

How do you know it's stopping at 'cd /library/webserver' ?
And IF it is stopping there, does the user under which the script is running have permissions to cd to that directory?

jackonapsp 05-20-2011 12:22 AM

still didn't work
 
Ok i run the script your way and itunes didn't pause and where exactly is the log.txt?

lrtward 05-22-2011 04:14 PM

It is logs.txt, not log.txt, and it will be in the same directory as your script. If you provided a path to logs.txt (echo "after content-type >> /tmp/logs.txt") then the file would be in /tmp. But since you do not specify any path, then logs.txt is "here", or in other words it is in the same directory as the script.

jackonapsp 05-23-2011 01:14 AM

Have figured why the script isn't running but there is anther problem
 
Ok i found out why it isn't working the script that i run from the web runs another script that controls itunes. I opened the script up in text edit (the one that controls itunes) and found this osascript -e 'tell application "iTunes" to play' and i tried that from terminal while itunes was open and it worked. But then i put that command in a different script and tried it from the web and it didn't work. SO i was just wondering how would you change the apache2 user (www) to be able to run the command or what permissions does the user (www) have to have before it can run the command?

Any help would be much appreciated


All times are GMT -5. The time now is 03:29 PM.