Run Program from Bash CGI-Script

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Run Program from Bash CGI-Script
# 1  
Old 01-27-2011
Run Program from Bash CGI-Script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
This is a problem I am having with my 2 semester senior project. I have a LAMP server running Ubuntu 9.10 with gnome that I need to run a program on from a button on its website. I'm using 'xterm -e vlc'. A member cero pointed out that I needed to include the display name which is ':0.0', I got when I ran 'echo $DISPLAY' in the terminal. I can run 'xterm -e vlc' in a terminal and 'xterm -display :0.0 -e vlc' in a terminal. However, it doesn't work in a bash cgi script.

I also tried adding localhost before ':0.0' to see if that works, but it didn't.

In short words, I need a program to run on the server from a button on the website. Nothing from the cgi-scrip needs to be displayed on the website.

The website is: Crimson Security - Home if you want to check it out.


2. Relevant commands, code, scripts, algorithms:
xterm -display :0.0 -e vlc
xterm -e vlc
xterm -display localhost:0.0 -e vlc


3. The attempts at a solution (include all code and scripts):
Code:
#!/bin/bash
echo "Content-type: text/html"
echo ""

xterm -e vlc

echo "<html><head><title>Crimson Security - Redirect"
echo "</title></head><body>"

echo "<h1>You have started VLC Media Player</h1>"
echo "Today is $(date)"
echo "<br><br>"
echo "<A HREF='javascript:history.go(-1)'>Go Back</a>"

echo "</body></html>"

Also tried:
Code:
#!/bin/bash
echo "Content-type: text/html"
echo ""

#main line of code that I need to work
xterm -display localhost:0.0 -e vlc
#####################

echo "<html><head><title>Crimson Security - Redirect"
echo "</title></head><body>"
echo "<h1>You have started VLC Media Player</h1>"
echo "Today is $(date)"
echo "<br><br>"
echo "<A HREF='javascript:history.go(-1)'>Go Back</a>"

echo "</body></html>"

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
The University of Alabama; Tuscloosa, AL; Dr. Kenneth Ricks; ECE 494 Capstone Design -- The University of Alabama

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Edit: If I forgot something, please let me know.
Original post is located here: https://www.unix.com/shell-programmin...gi-script.html

Last edited by JMooney5115; 01-27-2011 at 03:44 PM..
# 2  
Old 01-27-2011
You can't dump an executable in your webspace and expect the server to run it, most are only configured to run executables they find in special /cgi-bin/ directories. If you put your script under /var/www/localhost/cgi-bin/scriptname and open http://my.web.page/scriptname, it might go.
# 3  
Old 01-27-2011
Well, the xterm holds up the script from timely termination. Put it in a "nohup ... & 2>/dev/null". Remember it will want to extend a log nohup.out in $PWD. It might work better to export the DISPLAY, as I find -d sometimes does not. If vlc is X, why does it need an xterm?
# 4  
Old 01-27-2011
Coronal688: All my scripts are in the /cgi-bin/ directory where apache2 looks.

DGPickett: vlc is just a the program I am testing to see if I can successfully run a program from cgi-script. It isn't what I need to run. I tried "nohup xterm -display :0.0 -e vlc & 2>/dev/null" but nothing different happened.

It is as if 'xterm -display :0.0 -e vlc' is just skipped. The actual script I am executing is here: Crson Security - Redirect

Last edited by JMooney5115; 01-27-2011 at 04:05 PM..
# 5  
Old 01-27-2011
Quote:
Originally Posted by JMooney5115
It is as if 'xterm -display :0.0 -e vlc' is just skipped.
Hmm -- maybe it is. Might not be in the PATH apache gives you. Try calling it with an absolute path. You could also 'source /etc/profile' in case there's other mysterious variables libx11 needs.

For that matter: Apache might just plain be being denied permission to connect to the local X server. Usually these days it only allows someone who's logged into X11 to pop up windows on it.
# 6  
Old 01-27-2011
I changed the path to /usr/bin/vlc, didn't work. Also, 'source /etc/profile' does nothing. I tried in the terminal '/usr/bin/vlc /etc/profile' since I'm unsure of the use of 'source /etc/profile' and vlc just ran.

The use when the script is ran is 'www-data'. Could this be an error due to it being ran as that user?
# 7  
Old 01-27-2011
Your local X server probably doesn't let any user but the one who logged into X pop up windows. xhost + as that user might help,but I'm not sure.

In any case, if this X window really isn't really a part of the project, maybe there's a better way to signal you that it succeeded? Could you make the server's PC speaker beep or something? (install the beep utility, setuid it, then just /usr/bin/beep)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to convert my /bin/sh script with cgi and html to run it on browser!??

Hello, I want to run this script on my CentOS 6 via browser : ________________________________________________________________________________________________ #!/bin/sh echo Username? read MY_NAME echo Provisional file name? read MY_FILE echo File NAME you want to save? read MY_FILE2... (16 Replies)
Discussion started by: juta2020
16 Replies

2. Shell Programming and Scripting

Run command through html+cgi in bash

Hi everyone, I want to kill process through the web, so I create html page with single bottom that run kill command in shell script with CGI. Here is html code: <td><form METHOD="GET" action="http://IP:port/cgi_bin/script.cgi" > <input type="submit" value= "Submit" > <INPUT name="q"... (7 Replies)
Discussion started by: indeed_1
7 Replies

3. Programming

Calling bash script from CGI

Hi, I am having two individual scripts Script 1): CGI script - is a simple script which trigger bash script Script 2): Bash script - is a script which execute which collects file system utilization information from all the Unix servers If I am executing CGI script manually from command... (2 Replies)
Discussion started by: Naveen.6025
2 Replies

4. UNIX for Beginners Questions & Answers

How to run script through CGI?

Hi I have written a script and I want it to be run from web with the help of CGI. can you please guide me . below script is working fine if run from backend but not sure how I should run through web. #!/bin/bash string1=look string2=0 string3=.sdn.dnb echo -n "enter... (3 Replies)
Discussion started by: scriptor
3 Replies

5. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/gdg.sh -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC gdg.sh will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

6. Shell Programming and Scripting

Delete Files with CGI Bash Script

Hi. I could use some help with my problem. I am creating a website. One option on this website is to delete a specified file, say an image, when the user clicks on it. I want to do this with CGI. I believe bash will be the easiest since I will just type the command "rm file". I also do not know... (4 Replies)
Discussion started by: JMooney5115
4 Replies

7. Shell Programming and Scripting

[bash] Run a program many times

Hi I'm running a program many times with differents input. I mean that i run my_prog with some parameters and i wait till the end, then i start again another simulations with some others differents parameters. Is possible to make it automatic with a script bash. Maybe i need some... (2 Replies)
Discussion started by: Dedalus
2 Replies

8. Shell Programming and Scripting

how to run cgi -script on Cygwin ?

All, I would like to run a cgi script in cygwin which i have installed in WinXP. My CYGWIN directory structure is /var/www/ drwxrwx---+ 2 user Users 0 Nov 23 16:24 cgi-bin drwxrwx---+ 3 user Users 0 Oct 22 17:21 htdocs drwxrwx---+ 3 user Users 0 Oct 22 17:22 icons and another... (1 Reply)
Discussion started by: jambesh
1 Replies

9. Shell Programming and Scripting

Wrapping a bash script for CGI

I hope its ok to start a new thread, I was going to use my existing one but thought a new one would better clarify things and provide better search for future reference. Well I have my bash program working now, all nice, user input validated, output formatted, everything is looking sexy. Now... (2 Replies)
Discussion started by: andyj
2 Replies

10. UNIX for Dummies Questions & Answers

Run ksh script from cgi

Hi, I'm developing a system which requires me to run a ksh script from within a cgi script. What sort of syntax will I need to do this, I'm sure it's simple but can't find out how anywhere! Thanks. (2 Replies)
Discussion started by: hodges
2 Replies
Login or Register to Ask a Question