LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-10-2011, 01:47 AM   #1
jackonapsp
LQ Newbie
 
Registered: Jul 2010
Location: /home
Distribution: tty linux
Posts: 17

Rep: Reputation: 0
Unhappy 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.
 
Old 05-10-2011, 04:21 AM   #2
baltho
Member
 
Registered: Aug 2004
Location: Adelaide, South Australia
Distribution: Ubuntu (Natty)
Posts: 38

Rep: Reputation: 18
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...
 
Old 05-10-2011, 07:34 AM   #3
lrtward
Member
 
Registered: Feb 2011
Distribution: CentOS, Ubuntu
Posts: 97

Rep: Reputation: 9
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.
 
Old 05-11-2011, 02:47 AM   #4
jackonapsp
LQ Newbie
 
Registered: Jul 2010
Location: /home
Distribution: tty linux
Posts: 17

Original Poster
Rep: Reputation: 0
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
 
Old 05-19-2011, 01:02 PM   #5
lrtward
Member
 
Registered: Feb 2011
Distribution: CentOS, Ubuntu
Posts: 97

Rep: Reputation: 9
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?
 
Old 05-20-2011, 12:22 AM   #6
jackonapsp
LQ Newbie
 
Registered: Jul 2010
Location: /home
Distribution: tty linux
Posts: 17

Original Poster
Rep: Reputation: 0
still didn't work

Ok i run the script your way and itunes didn't pause and where exactly is the log.txt?
 
Old 05-22-2011, 04:14 PM   #7
lrtward
Member
 
Registered: Feb 2011
Distribution: CentOS, Ubuntu
Posts: 97

Rep: Reputation: 9
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.
 
Old 05-23-2011, 01:14 AM   #8
jackonapsp
LQ Newbie
 
Registered: Jul 2010
Location: /home
Distribution: tty linux
Posts: 17

Original Poster
Rep: Reputation: 0
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
 
  


Reply

Tags
apache2, itunes, server, shell script, webserver



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] PHP enabled server won't run a script that works on other servers. devwink Linux - Server 6 02-12-2010 03:39 PM
in bash shell how to run shell script during startup rammohan04 Red Hat 2 07-31-2009 02:07 AM
run a shell script on remote client from a server to find all its running process robin singh Linux - Newbie 7 10-03-2008 11:32 AM
Cannot run shell script on the remote server haresh_dba Linux - General 2 04-14-2007 09:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration