Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
04-11-2008, 04:10 AM
|
#1
|
|
LQ Newbie
Registered: Oct 2007
Posts: 10
Rep:
|
Running a BASH Script within PERL pm
I want to run a bash script within a perl script using perl-cgi
1. User will enter a number in the form page
2. Form will call a URL pointing to a .pm program
3. pm script runs and processes a bash program
I can't get my action page to write a file: /var/www/cgi-bin/date.txt
See below.
Anyone knows how.
1. Form page:
#!/usr/bin/perl
use strict;
use CGI;
my $cgi = new CGI;
print
$cgi->header() .
$cgi->start_html(-title =>'Testing the Form') .
$cgi->h1('Test Forms using PERL!') .
$cgi->startform ('POST', '/cgi-bin/processForm.pm') .
$cgi->textfield(-name=>'username', -default=>'Admin', -size=>'10', -maxlength
=>'10') .
$cgi->submit(-name=>'submit', -value=>'Send') .
$cgi->endform () .
$cgi->end_html;
exit (0);
2. Action page
#!/usr/bin/perl
use strict;
use CGI;
my $cgi = new CGI;
print
$cgi->header() .
$cgi->start_html(-title =>'Form Results') .
$cgi->h1('Form Results using PERL!') ;
my $user = $cgi->param('username');
print "<H4>";
print "$user</H4><H4>\n";
exec("/var/www/cgi-bin/echoDate.sh");
print "</H4>\n";
print $cgi->end_html;
exit (0);
3. Bash program
#/bin/sh
echo $(date "+%d %b %Y") >> /var/www/cgi-bin/date.txt
#touch /var/www/cgi-bin/hello.txt
|
|
|
|
04-11-2008, 09:03 PM
|
#2
|
|
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530
Rep:
|
There's a much better way to get a date string than shelling out to the date command... See the manual page for the Date::Format module.
|
|
|
|
04-12-2008, 12:07 PM
|
#3
|
|
LQ Newbie
Registered: Oct 2007
Posts: 10
Original Poster
Rep:
|
Quote:
Originally Posted by matthewg42
There's a much better way to get a date string than shelling out to the date command... See the manual page for the Date::Format module.
|
Thanks for replying. The script above is to test a concept. The actual bash script will contain several commands which may need to write to a log file. If I don't write the part ">> <file>", the date shows in the response page. But if I add that part, I expect the date to be written into the file.
|
|
|
|
04-15-2008, 10:22 AM
|
#4
|
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
|
When you use exec() to launch your bash script, the perl script terminates. If you really want to do it this way (and I can't imagine why you would ever want to drop to a bash script from perl), you can either fork() a child process to launch the shell script, or use the system() perl command, use the `backtick` format of the command, or...
Probably, your cgi-bin directory is [correctly] configured with permissions disallowing writes by the web server. To allow Write-Execute permission would be a security issue. Use a directory with no execute permission.
--- rod.
|
|
|
|
05-10-2008, 12:09 AM
|
#5
|
|
LQ Newbie
Registered: Oct 2007
Posts: 10
Original Poster
Rep:
|
Quote:
Originally Posted by theNbomr
Probably, your cgi-bin directory is [correctly] configured with permissions disallowing writes by the web server. To allow Write-Execute permission would be a security issue. Use a directory with no execute permission.
--- rod.
|
Thanks theNbomr.
No more BASH in my scripts, just PERL.
You were right, Apache was running as "apache", and the log files in /var/log/* were showing write permission errors.
Getting the script to work is a matter of setting the right permissions.
|
|
|
|
All times are GMT -5. The time now is 06:27 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|