Results 1 to 7 of 7
Thread: PHP calling shell script
-
08-11-2004, 05:04 PM #1Newbie
- Join Date
- Aug 2004
- Posts
- 7
PHP calling shell script
Hello
I need to use PHP to pass parameter values
to shell
but I don't know how to do it!!
pls help!
thanks a lot
-
08-11-2004, 06:06 PM #2Web Hosting Master
- Join Date
- Nov 2003
- Posts
- 691
Look at these functions
http://php.net/exec
http://php.net/system
-
08-12-2004, 07:52 AM #3Newbie
- Join Date
- Aug 2004
- Posts
- 27
hm
if you do a
./php testvar.php -f=plah -g=pleh ,xyz=fnuk
to start your php from shell
then try "testvar.php" with the following code
#!/usr/bin/php
<?
var_dump($argv);
?>
i guess its what youre looking for
-
08-12-2004, 10:18 AM #4Newbie
- Join Date
- Aug 2004
- Posts
- 7
I try that
Umm I try to make usershow.sh to recieve from viewuser.php
in php file I can use exec() to run usershow.sh
but I want to pass parameter such as $username
to shell script but I don't know how to write shell to recieve and how php pass value to shell by use exec() or system()
Thanks for every one
-
08-12-2004, 10:45 AM #5Newbie
- Join Date
- May 2002
- Location
- Finland
- Posts
- 11
I hope this gives you an idea, if i understood you correctly try this:
PHP part:
<?php
system('/path/to/test.sh variable1');
?>
Shell (bash) part:
#!/bin/bash
echo $1
Chmod the .sh with something like 755 and then run your php script
-
08-12-2004, 10:52 AM #6Newbie
- Join Date
- Aug 2004
- Posts
- 27
hm
if you want to pass params during the runtime, you need to use any stream for.
i.e.
you can read a textfile for new lines
also you could stress mysql (selecting a table)
or you implement a socketlistener (AF_UNIX) to your script
else threre is no chance to passing vars during the scriptruntime. Not that i know.
-
08-12-2004, 02:56 PM #7Newbie
- Join Date
- Aug 2004
- Posts
- 7
It still not work for use php to pass value to shell
I'm ok to write shell to recieve parameter form console
but pass with PHP is still not work
example
I write
on PHP
<?
shell_exec(" ./mkdir.sh newdir ");
?>
on shell
#!/bin/bash
mkdir $1
and chmod 755 with shell
I can run shell by command line ./mkdir.sh new_dir
It's OK
What should I do in this way or I have another problem with server sevice because my RH9 server is not compleately runing well
Thanks a lot for every one