Solved

Triggering perl scripts from a web page

Posted on 2011-03-13
2
369 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

737 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