Execution problem unix commands in Perl CGI
I am trying to run SSH , mkdir and other unix commands using Perl CGI. But i am not able to Execute these commands.
Please help me out !!!!
SSH and mkdir is necessity for me.
I will be thankful to you...!!!!!
I am trying like:
In perl CGI file i am writing like: @list = `ssh username@machinename 'ls /global/directory_name'`;
In what way does it "not work"? What is the code which is "not working"?
From another thread:
Is ssh configured to login without a password, there? You'll probably need to tell it what key files to use with ssh -i /path/to/key. You'll need to give the key the right permissions so the webserver can read it, too.
---------- Post updated at 10:43 AM ---------- Previous update was at 10:41 AM ----------
You may also find it useful to redirect standard error into standard output so you can see error messages from shell programs instead of them all being swallowed by the web server. Unfortunately, while trivial in a shell , that's extremely difficult in perl.
---------- Post updated at 10:52 AM ---------- Previous update was at 10:43 AM ----------
"right permissions" so a webserver can read it would probably be 0600 or 0400, owned by apache:root
i am running command like: system("mkdir dirname") and @array= `ssh username@machinename 'ls directoryname'` in demo.pl. which is fine.
If i run the same commands in demo.cgi in web browser then these commands are not working..
PLease help me out...
Your CGI script gets run as the user apache, probably, which isn't you.
I repeat. system() isn't an alternative to shell scripting. system() is an entire, real shell. System is actually the same shell you were hoping to avoid by using perl!
You are running shell scripts.
You are loading entire bourne shells, running single 'mv file1 file2' commands in them, quitting entire shells, then doing it again, over, and over, and over. You are running, potentially, dozens or hundreds of tiny, individual, shell scripts.
And you're running them in an especially slow, wasteful, and bug-prone way, having to tiptoe around perl to get the raw text you wanted into and out of the shell. You can't even get your error messages!
If you post your perl code, I'll show you how to do it in a shell script, and show you how to do it in a way that will work in CGI.
Buddy i am just doing like:
In Demo.pl #This is working well on the Unix terminal which is fine.
system("mkdir -p /dirname/dirname"); # it is creating directory which is fine.
@array = `username@machine_name 'ls dirname'`; # It is giving list of files available on this directory
In Demo.cgi #this is not working well.
use CGI qw(:standard)
system("mkdir -p /dirname/dirname"); # it is not creating directory which is fine.
@array = `username@machine_name 'ls dirname'`; # It is no tgiving list of files available on this directory
@arr = `ls dirname`; # it is working fine
In Demo.html # in this html i am calling Demo.cgi which is not executing ssh & mkdir
<body><form action="Demo.cgi" method="GET">
Enter some text here:
<input type="text" name="sample_text" size=30><input type="submit"><p></form>
Please Give me any solution what should i do... i am almost pissed off with it.. Plezzz.
---------- Post updated at 11:29 PM ---------- Previous update was at 11:28 PM ----------
I have shown you some piece of code which i need no fix ... please give me some solution.
We are not here 24/7. If you don't get an answer immediately, wait!
Thanks for posting your code. Finally, finally, I can answer some of your questions.
And since your code is nothing but tightly stretched shrinkwrap over 99% shell script, you could also try this CGI script:
No I am not forgetting ssh there i am creating directory in local Unix machine.
I didn't get exactly your answer.
# chown :apache /dirname ## i didn't gat apache here what does it means here.
# chmod g+w /dirname
where i have to do these actions :
On terminal or in the .cgi script ?
what is the alternative for SSH. I just want to get list of files from there ???
|All times are GMT -4. The time now is 09:49 AM.|
Linux and Unix Supported by: vBulletin
Search Engine Optimisation provided by DragonByte SEO v1.1.4 (Pro) - vBulletin Mods & Addons Copyright © 2014 DragonByte Technologies Ltd.
The UNIX and Linux Forums Content Copyright ©1993-2013. All Rights Reserved.
Forum Operations by The UNIX and Linux Forums