
26th June 2006, 05:52
|
|
Member
|
|
Join Date: Jun 2006
Posts: 66
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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.
|

27th June 2006, 10:20
|
|
Super Moderator
|
|
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 31,853
Thanks: 781
Thanked 1,558 Times in 1,477 Posts
|
|
|

28th June 2006, 01:36
|
|
Member
|
|
Join Date: Jun 2006
Posts: 66
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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
|

8th August 2006, 17:30
|
|
Senior Member
|
|
Join Date: Oct 2005
Location: Texas, USA
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
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 01:04.
|
Recent comments
16 hours 32 min ago
21 hours 47 min ago
21 hours 58 min ago
22 hours 6 min ago
23 hours 8 min ago
1 day 1 hour ago
1 day 3 hours ago
1 day 4 hours ago
1 day 4 hours ago
1 day 5 hours ago