Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 26th June 2006, 05:52
alexnz alexnz is offline
Member
 
Join Date: Jun 2006
Posts: 66
Thanks: 3
Thanked 1 Time in 1 Post
Default php scripting and shell commands

just too start this off im a completely newbie when it comes too php scipting so im asking for a little help with a couple of things, once i have a working example of something ill then be able too learn from it then expand it too other things i would like done:

firstly - the look of it:

have a list of 10 fields from which i can enter text information too

a list of 10 radio buttons from where i can only choose one radio button

a "go" button at the bottom that then runs the script, and a "clear" button that resets the form


backend:

basicly i want too be able too run shell scripts from PHP once the information has been entered for example (i dont know the correct syntax if someone can correct me)

once the information is entered, lets just use field1 and field2, and the user has choosen radio button1 it will run script1.sh with field1 information,

field1 would usually be a username ie: web1_user1
field2 would usually be a specified directory ie: custom1 or template1

radio button 1 example:

inside script1.sh i would like it too be copying files from one static directory ie /var/www/texmplate1 too a dynamic directory specified by field2ie: /var/www/$field2/web

radio button 2 example

if they choose button2 i would like a file too be created lets make it a .htaccess file, i would then like the following field1 and field2 entered into it when the .htaccess file is created example:

AuthType Basic
AuthName "Members Only"
AuthUserFile /var/www/$field1/.htpasswd
<limit GET PUT POST>
require valid-user
</limit>

then once the file is created itll put it into a directory labelled by $field2 ie: copy .htaccess /var/www/$field1/web/$field2




if someone could type up my examples i can then learn from it and build up my scripting from there thanks!



thanks too anyone that can help!

Last edited by alexnz; 26th June 2006 at 06:09.
Reply With Quote
Sponsored Links
  #2  
Old 27th June 2006, 10:20
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,747 Times in 2,578 Posts
Default

Maybe these two tutorials help you: http://codewalkers.com/tutorials.php?show=12
http://www.freewebmasterhelp.com/tutorials/php/6
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #3  
Old 28th June 2006, 01:36
alexnz alexnz is offline
Member
 
Join Date: Jun 2006
Posts: 66
Thanks: 3
Thanked 1 Time in 1 Post
Default

thanks falko they have alot

i purchased me a book too : learning php5 by david sklar - published by o'reilly books

see how its goes, wish me luck!

oh once ive built my script ill post it up here so others can get a jump start into php with shell scripting
Reply With Quote
  #4  
Old 8th August 2006, 17:30
themachine themachine is offline
Senior Member
 
Join Date: Oct 2005
Location: Texas, USA
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
 
Default

I believe the function you're looking for is 'shell_exec()':

http://us3.php.net/shell_exec


You can pass the 'field1' and 'field2' variable via command line to the shell script as well.

Something like this is what you are going to be doing:

The PHP Script:
Code:
<?php
$field1 = $_POST['field1'];
$field2 = $_POST['field2'];
...
if ($something == "something") {
     if(shell_exec('/path/to/shell_script1.sh $field1 $field2')) {
          print "The shell script executed without error!";
     } else {
          print "The shell script returned with an error!";
     }
} elseif ($something == "somethingelse") {
     if(shell_exec('/path/to/shell_script2.sh $field1 $field2')) {
          print "The shell script executed without error!";
     } else {
          print "The shell script returned with an error!";
     }
}
...
?>

What you are doing is passing '$field1' and '$field2' as a parameter to the shell script. Therefore, the shell script will look something like this:

Code:
#!/bin/bash

# $1 is the first parameter passed to the shell script
field1=$1
field2=$2

# Do whatever you want with the $Field1 and $field2 variable
#
# Such as /var/www/${field2}/web
#
# OR 
#
# AuthType Basic
# AuthName "Members Only"
# AuthUserFile /var/www/${field1}/.htpasswd
# <limit GET PUT POST>
#        require valid-user
# </limit>

Using brackets for the variables isn't necessary, but whenever I am embedding them like that in a line where there is no whitespace around the variable, I like to.

Hope that helps
__________________
themachine
5dollarwhitebox.org

Last edited by themachine; 8th August 2006 at 17:36.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Impressive shell scripting namit Programming/Scripts 8 25th March 2006 16:50


All times are GMT +2. The time now is 04:24.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.