Running a shell script in apache


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running a shell script in apache
# 1  
Old 03-02-2010
Running a shell script in apache

I have a shell script, that works when ran in the shell. When placed in the cgi-bin directory, it doesn't work as expected.

Looking at the logs, it seems that some environmental variables are not being passed.

My apache user is www.

For simplicity, here is a sample script I want to run

Code:
#!/usr/bin/bash

echo "$HOME"

When logged in as user "www" from a shell it will return

Code:
/home/www

When running the script from a hyperlink I get no output. How can I resolve this?

Thanks
# 2  
Old 03-02-2010
The script has to source the environment variables/settings all by itself -
source /home/phpuser/.profile
source /etc/profile

emulate what occurs during login. Whatever that is. test you efforts first with the "set" command - it shows everything.
It should match what you get when you run it interactively.
# 3  
Old 03-03-2010
Quote:
Originally Posted by jim mcnamara
The script has to source the environment variables/settings all by itself -
source /home/phpuser/.profile
source /etc/profile

emulate what occurs during login. Whatever that is. test you efforts first with the "set" command - it shows everything.
It should match what you get when you run it interactively.
I added a .profile to /home/www

However, I still don't get the output of echo "$HOME"

---------- Post updated at 11:28 AM ---------- Previous update was at 10:41 AM ----------

You can disregard my last post, I figured it out.

Thanks for the help!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Process not running: /opt/java15/jdk/bin/java -classpath /opt/apache/apache-ant-1.7.0-mod/lib/ant-la

Have no idea on what the below error message is: Process not running: /opt/java15/jdk/bin/java -classpath /opt/apache/apache-ant-1.7.0-mod/lib/ant-launcher.jar org.apache.tools.ant.launch.Launcher -buildfile build.xml dist. Any help? (3 Replies)
Discussion started by: gull05
3 Replies

2. Shell Programming and Scripting

Cp not working in shell script but running perfectly from shell

Dear All, I have script. Dest="" IFS=' ' for translation in $(echo $MY_MAP) do t1=$(echo $translation | cut -d"=" -f1) t2=$(echo $translation | cut -d"=" -f2| cut -d"," -f1) if then Dest=$UNX/$u_product_path/$u_study_path/$UNXTR/$t2 break; ... (4 Replies)
Discussion started by: yadavricky
4 Replies

3. Shell Programming and Scripting

Changing shell from a script and running something from the new shell

Hi We use "tcsh" shell . We do the following steps manually: > exec ssh-agent zsh > python "heloo.py" (in the zsh shell) I am trying to do the steps above from a shell script This is what I have so far echo "Executing " exec ssh-agent zsh python "hello.py" exit 0 Problem is... (5 Replies)
Discussion started by: heman82
5 Replies

4. Shell Programming and Scripting

Shell Script for continuously checking status of a another script running in background, and immedia

Hi, I want to write a script which continuously checking status of a script running in background by nohup command. And if same script is not running then immediately start the script...please help.. i am using below command to run script nohup system_traps.sh & but in some... (9 Replies)
Discussion started by: ketanraut
9 Replies

5. Shell Programming and Scripting

Script to restart apache when running out of memory

Hi, I have a problem with running out of memory in my Ubuntu web server (4GB RAM) because many people try to access my server. I used to restart manually my apache server to clear out the memory & swap. Can anyone tell me how to write bash script that can automatically restart apache when... (2 Replies)
Discussion started by: nica
2 Replies

6. Shell Programming and Scripting

Apache Hosting-Shell Script - external files include

Hi there Well, it's my first time on this board, so short to myself: I'm matibaski, working as a webdeveloper and also as a system administrator on ubuntu server machines. The problem: I created a small apache-hostingscript by myself and it works fine. But after some addings and new... (1 Reply)
Discussion started by: matibaski
1 Replies

7. Shell Programming and Scripting

Shell script running command in different shell

Hi All, Is there any way where we can run few commands with different shell in a shell script ? Let's have an example below, My first line in script reads below, #!/bin/sh However due to some limitation of "/bin/sh" shell I wanted to use "/bin/bash" while executing few... (9 Replies)
Discussion started by: gr8_usk
9 Replies

8. UNIX for Advanced & Expert Users

Shell script to parse apache httpd line

Hello, I have serveral SUN Web servers that need to write a KSH to figure out where Apache is installed and, tar up the directory (for backup purposes) once a month. The trick is that Apache is not installed in same location. So when I do "ps -ef| grep httpd" it shows on some boxes from... (2 Replies)
Discussion started by: afadaghi
2 Replies

9. Solaris

Running from Shell Vs running from RC script

Hi, i have a script which need to do behave differently when run as a startup process from init.d/ rc2.d script and when run manually from shell. How do i distinguish whether my script is run by init process or by shell?? Will the command /proc/$$/psinfo | grep "myscript" work well???... (2 Replies)
Discussion started by: vickylife
2 Replies

10. Shell Programming and Scripting

need help: shell script to restart apache when no. of processes keeps growing

I need a shell script to kill apache and restart it, in case the number of processes keeps growing. The logic is like the below, but I don't know how to get the number and neither the syntax. Could somebody kindly help? if no_of_processes (ps ax ¦ grep httpd) > 200 then killall httpd... (14 Replies)
Discussion started by: _joshua_
14 Replies
Login or Register to Ask a Question