Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > running UNIX with perl

Reply
Thread Tools

running UNIX with perl

 
 
joe
Guest
Posts: n/a
 
      06-27-2003
Dear Gurus,

I got stuck at the following. I've tried running a UNIX command in my Perl
CGI-script, but it doesn't work the way I expected it to. When I run the
next line:

$ls = `ls > file.txt`; or
system("ls > file.txt");

everything is ok. So running a UNIX command is not a problem an sich. But
when I run something like:

$ls = `man perl > file.txt`; or
system("mysqldump --user=username --password='password' dbname tablename >
file.txt");

an empty text-file is the result. How come? I'm a verry happy man already
knowing someone can help me out.

TIA

Joe


 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      06-27-2003
"joe" <> writes:

> I got stuck at the following. I've tried running a UNIX command in my Perl
> CGI-script, but it doesn't work the way I expected it to. When I run the

^^^^^^^^
> next line:
>
> $ls = `ls > file.txt`; or
> system("ls > file.txt");
>
> everything is ok. So running a UNIX command is not a problem an sich. But
> when I run something like:
>
> $ls = `man perl > file.txt`; or
> system("mysqldump --user=username --password='password' dbname tablename >
> file.txt");
>
> an empty text-file is the result. How come? I'm a verry happy man already
> knowing someone can help me out.


Have you tried these things from a command line script? Perlhaps you
are getting problems because of the CGI environment.

Are these failing commands emitting anything on STDOUT? (Would you know if
they were?).

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
Reply With Quote
 
 
 
 
Thens
Guest
Posts: n/a
 
      06-27-2003
On Fri, 27 Jun 2003 17:16:06 GMT
"joe" <> wrote:

>Dear Gurus,


>everything is ok. So running a UNIX command is not a problem an sich. But
>when I run something like:


Yes. The problem is not with running unix commands.

>$ls = `man perl > file.txt`; or
>system("mysqldump --user=username --password='password' dbname tablename >
>file.txt");


>an empty text-file is the result. How come? I'm a verry happy man already
>knowing someone can help me out.


CGI programs run in the server as user nobody.

* Never use relative paths for accessing files
* Use absolute paths for system executables.

You might try

system("/usr/local/bin/mysqldump --user=username --password='password' dbname tablename > file.txt")

or wherever the installation is. And also how are you accessing the file 'file.txt'. Be sure to access it from the right place.

Regards,
Thens.
 
Reply With Quote
 
joe
Guest
Posts: n/a
 
      06-27-2003
Thanks for the quick response, but i'm nu further. I made a shell script
with the following lines:

echo test1 > /opt/guide/www.secretaressebank.nl/HTML/dev/dbdump.txt
mysqldump --user=username --password='password' dbname tablename >> file.txt
echo test2 >> /opt/guide/www.secretaressebank.nl/HTML/dev/dbdump.txt

When i exec this from the bash, it works just fine. But when i run it
through a CGI-script, it 'forgets' to execute the second and most important
line. Does it have anything to do with the rights? The CGI-script's rights
are 755, the shell script's are 777.

TIA again!


 
Reply With Quote
 
Thens
Guest
Posts: n/a
 
      06-27-2003
On Fri, 27 Jun 2003 18:00:19 GMT
"joe" <> wrote:

>Thanks for the quick response, but i'm nu further. I made a shell script
>with the following lines:
>
>echo test1 > /opt/guide/www.secretaressebank.nl/HTML/dev/dbdump.txt
>mysqldump --user=username --password='password' dbname tablename >> file.txt
>echo test2 >> /opt/guide/www.secretaressebank.nl/HTML/dev/dbdump.txt
>
>When i exec this from the bash, it works just fine. But when i run it
>through a CGI-script, it 'forgets' to execute the second and most important
>line. Does it have anything to do with the rights? The CGI-script's rights
>are 755, the shell script's are 777.

 
Reply With Quote
 
Matthew Weier O'Phinney
Guest
Posts: n/a
 
      06-27-2003
* joe <>:
> Thanks for the quick response, but i'm nu further. I made a shell script
> with the following lines:
>
> echo test1 > /opt/guide/www.secretaressebank.nl/HTML/dev/dbdump.txt
> mysqldump --user=username --password='password' dbname tablename >> file.txt
> echo test2 >> /opt/guide/www.secretaressebank.nl/HTML/dev/dbdump.txt
>
> When i exec this from the bash, it works just fine. But when i run it
> through a CGI-script, it 'forgets' to execute the second and most important
> line. Does it have anything to do with the rights? The CGI-script's rights
> are 755, the shell script's are 777.


It looks like the problem is that the CGI environment path is different
than your bash path -- which means it can't find where the mysqldump
executable is. In bash, type 'which mysqldump', and then copy the full
path it gives you to both your shell script and perl script -- I think
you'll find it works now.

The next thing to do if it doesn't work is to find out whether or not
the mysqldump executable has permissions that allow the CGI environment
to execute it. If it's permissions allow execution by the CGI
environment's user, group, or world permissions, than it should work; if
not, well, you're pretty much hosed.

--
Matthew Weier O'Phinney
http://weierophinney.net/matthew/
 
Reply With Quote
 
Thens
Guest
Posts: n/a
 
      06-27-2003
On Fri, 27 Jun 2003 18:00:19 GMT
"joe" <> wrote:

>Thanks for the quick response, but i'm nu further. I made a shell script
>with the following lines:
>
>echo test1 > /opt/guide/www.secretaressebank.nl/HTML/dev/dbdump.txt
>mysqldump --user=username --password='password' dbname tablename >> file.txt
>echo test2 >> /opt/guide/www.secretaressebank.nl/HTML/dev/dbdump.txt


Monitor the STDERR, in CGI the servers error log for the details.

>When i exec this from the bash, it works just fine. But when i run it
>through a CGI-script, it 'forgets' to execute the second and most important
>line. Does it have anything to do with the rights? The CGI-script's rights
>are 755, the shell script's are 777.


Ignore the other reply.

When you execute it from a bash your environment is set to access
mysqldump from your PATH settings. But in a CGI environment your PATH
settings are not known and hence you need to find out the actual
location of mysql in your system.

~home> which mysqldump

and invoke mysqldump with the absolute path in the shell script and the perl
script


Regards,
Thens.
 
Reply With Quote
 
joe
Guest
Posts: n/a
 
      06-27-2003
Great, using the exact address, captured by 'which mysqldump', was the
solution indeed!

Thanks a lot!


 
Reply With Quote
 
Martien Verbruggen
Guest
Posts: n/a
 
      06-27-2003
On Fri, 27 Jun 2003 21:06:52 GMT,
joe <> wrote:
> Great, using the exact address, captured by 'which mysqldump', was the
> solution indeed!


Great.

Now, to avoid all the mistakes that everyone has already made once
before while working in a CGI environment, please read the first
question in the Perl FAQ, section 9, and follow some of the links
suggested there.

Martien
--
|
Martien Verbruggen | Unix is user friendly. It's just selective
| about its friends.
|
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compile C programs with UNIX system calls (= Unix Programs??) jrefactors@hotmail.com C Programming 18 01-10-2005 03:35 AM
compile C programs with UNIX system calls (= Unix Programs??) jrefactors@hotmail.com C++ 12 01-10-2005 03:35 AM
my own perl "dos->unix"/"unix->dos" Robert Wallace Perl Misc 7 01-21-2004 11:28 PM
#!perl instead of #!/usr/bin/perl on a Unix/Apache webserver joe Perl Misc 8 11-14-2003 10:58 AM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57