Solved

Triggering perl scripts from a web page

Posted on 2011-03-13
2
367 Views
Last Modified: 2013-12-25
Hi folks,

I have an ubuntu server running a java/tomcat server that delivers an application.  I also use apache2 as an SSL reverse proxy.  I want to create a web page by which our helpdesk team can stop and start the java application as needed.

I have created a directory that is not proxied and a perl script (index.pl) that uses ps and grep to determine whether the java app is running and it displays a red or green light accordingly. So far, so good. I would now like a button or link to STOP TASK or START TASK.

I have created a pair of perl scripts to do this. They work from the command line but not when called via the web page. Would someone be able to point out where I've gone astray? Attached is the stop-app.pl script.

Thanks,
Sean


#!/usr/bin/perl
#
# Script to provide a page where users can stop and start the java app.
#
use warnings;
print "content-type: text/html \n\n"; # Tell perl to create some HTML
print "<html>\n";
print "<head>\n";
print "<title>myapp Admin Page</title>";
print "</head>\n";
print "<body>\n";
print "<center><h1>myapp Admin Page</h1><br />";

print "<img src='/myapp/hourglass.jpg' /><br />";
print "<h1>Java App is being shut down.</h1>\n";
print "<a href='/myapp/index.pl'><img src='/myapp/proceedbutton.gif' alt='Proceed' /></a>\n";

print "</center></body>\n";
print "</html>\n";

system("sudo service myapp stop");

# Here endeth the script.

Open in new window

0
Comment
Question by:srodden
2 Comments
 
LVL 12

Accepted Solution

by:
larsrohr earned 500 total points
ID: 35125578
Is your apache user (or whatever user runs your http processes) in your sudoers file?
It will need permission to run your "sudo service myapp stop" without being prompted for password.
0
 

Author Comment

by:srodden
ID: 35125598
Perfect, thank you!
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to create a textarea which saves text in HTML 8 62
Convert .csv to tab delimited text 11 49
BATCH to EXE Converter 2 67
IDE for Python 5 62
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question