Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i get perl to start a unix shell script?

Status
Not open for further replies.

mckarl

Programmer
May 5, 1999
147
GB
hi all, <br><br>I got my cgi baby rolling (kinda :) ) and i was wondering how i can get my cgi script to run my perl to begin a korn shell job??<br><br>Anyone know if it's possible??<br><br>i would probably use it across the network, ie, from this unix box along to the one in another part of the country across tcp/ip and then supply it my password and username and then launch the script, along with passing it a few variables sent from the script.<br><br>-- WAW!!<br><br>i know, i'v been to the doctors, they wondered why i havn't been in recently, and i told them i'v been ill..<br><br>Signing off, <br><br>Karl. <p>Karl Butterworth<br><a href=mailto:karl_butterworth@ordina.co.uk>karl_butterworth@ordina.co.uk</a><br><a href= > </a><br><i>I'm slim shadey, yes i'm the real shadey, all you other slim shadeys are just imitating; so wont the real slim shadey please stand up, please stand up, please stand up!</i>
 
There's a couple of ways to do this.&nbsp;&nbsp;The first is to use &quot;backtics&quot;, and the other is to use the &quot;system&quot; function call.<br><FONT FACE=monospace><br># Using backtics. Save the output from the shell<br># script in $Result_String.<br>$Result_String = `/some/script/to/run`;<br><br># Using system().&nbsp;&nbsp;Again, save the output from the script.<br>$Result_String = system(&quot;/some/script/to/run&quot;);<br></font><br>I tend to use system(), as I have more trust in it to evaluate scalars that contain paths to scripts, argements, etc. <p> <br><a href=mailto: > </a><br><a href= > </a><br>--<br>
0 1 - Just my two bits
 
if you wasnt so far away, i would kiss you.. (i hoping now that you are far away, and you are probably hoping the same too :))<br>BUT, what if i was to just let the script run, ie if i was to read data rfom the html, and then wanted the html input to be a username, and then the CFGI reads it, passed it through into my linux box, and wanted to run a program to see if that username was available, and then i wanted to save the ip address coming in, and loads of other things?<br>- would i still be able to run the program as if it was commanded from the terminal?? <p>Karl Butterworth<br><a href=mailto:karl_butterworth@ordina.co.uk>karl_butterworth@ordina.co.uk</a><br><a href= > </a><br><i>I'm slim shadey, yes i'm the real shadey, all you other slim shadeys are just imitating; so wont the real slim shadey please stand up, please stand up, please stand up!</i>
 
It depends...<br><br>Obviously, if the script needs some user intervention at some stage, then the answer is no.&nbsp;&nbsp;You're running the page from a browser, and there's no input stream...<br><br>If the script doesn't generate any output, but it does return an exit status, then I'd strongly suggest you have a read of <FONT FACE=monospace>perldoc -f system</font>.&nbsp;&nbsp;There's a note in there about the return codes from external scripts/programs as they are reported by perl.<br><br>If you have some control over the script, I would suggest you send some simple responses depending upon results you want to return.&nbsp;&nbsp;For example, if the user you are looking for exists, do an <FONT FACE=monospace>echo &quot;yes&quot;</font> in the shell script.&nbsp;&nbsp;Otherwise, <FONT FACE=monospace>echo &quot;no&quot;</font>.<br><br>Of course, the ultimate answer would be to replace the shell script with a function in your perl program.&nbsp;&nbsp;This might be easy, or it might be difficult.&nbsp;&nbsp;It all depends what you want to do :)&nbsp;&nbsp;You hinted that you want to see if a user exists - take a look at <FONT FACE=monospace>perldoc -f getpwent</font> for details on perl's &quot;get user details&quot; functions.<br><br>So, to summarise, it all depends how complex you want to get.&nbsp;&nbsp;I suggest taking a look at the shell scripts and re-writing them as perl functions.&nbsp;&nbsp;You will get some performance benefits (no sub-process being forked), and you will learn some more perl along the way.&nbsp;&nbsp;That's always a good thing! ;^)<br><br>PS, a thanks would have been fine, but I appreciate the sentiment ;^) <p> <br><a href=mailto: > </a><br><a href= > </a><br>--<br>
0 1 - Just my two bits
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top