LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-03-2004, 10:37 AM   #1
ibro
LQ Newbie
 
Registered: Nov 2003
Posts: 6

Rep: Reputation: 0
converting shell script to php script ?


Hello all,

I have just developed a shell script to perform some networking functions involving tc ,ip and ifconfig commands. I intend to make a GUI interface for this script so that i can change some variables of the script at ease and also a mysql database connection to store these parameters . Please is this possible without using perl scripting. if possible how.

On my own I have thought of converting the shell script to an php script by installing php-cli module and enclosing the script with <?php ?> but this has not worked. php can not recognise ifconfig ,tc shell commands .Can someone provide me hints on how to convert a shell script to php script with database connection feature. Thanks.

-Ibro
 
Old 05-03-2004, 04:27 PM   #2
nerdstat
LQ Newbie
 
Registered: Apr 2004
Location: Brussels, Belgium
Distribution: Gentoo with 2.6.8-kernel
Posts: 15

Rep: Reputation: 0
Code:
<?php
  system("ifconfig");
?>
The system-function is PHP calls starts programs as if you would call them at the shell... No special compile-options to php are needed to run this...
 
Old 05-03-2004, 04:33 PM   #3
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
Something to note...system() exec() passthru() and shell_exec() require safe mode to be turned off to run. If you want to keep safe mode on you need to copy the binaries you want to use to the safe_mode_exec_dir which is setup in php.ini

As for php database connectivity, there are a million good tutorials out there to get you started. Do a google for 'lamp tutorial' to find a bunch...
 
Old 05-14-2004, 08:45 AM   #4
ibro
LQ Newbie
 
Registered: Nov 2003
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks Bulliver and nerdstat,

I found your contributions very useful . But there is another question I want to ask.
Let me start by describing what I intend to do.:

I want this script, call it myscript to be executed at boot time .In the script, connection will be made to a mysql server from which will be read some values to be used as variables in the script .

At any time , I can change the values I have in my mysql server and I want this done through web interface using php form, so that when I restart my system , the script will execute with the new values.

Now can I use the web interface while I still use the CLI SAPI ?

Thanks.
 
Old 05-14-2004, 03:46 PM   #5
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
I was reading this page:

http://www.php.net/manual/en/features.commandline.php

and it appears that you can use both. The command line version needs you to put a bang line in your script like every other shell script ie:
#!/usr/bin/php

However: you may need to rebuild php and specify a make install-cli target, because although php builds both sapi's, only the cgi version is installed by default.

Hope this helps...
 
Old 05-16-2004, 10:54 AM   #6
ibro
LQ Newbie
 
Registered: Nov 2003
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks Bulliver,

I will try it and get in touch with the result.

Ibro
 
Old 05-24-2004, 05:19 AM   #7
ibro
LQ Newbie
 
Registered: Nov 2003
Posts: 6

Original Poster
Rep: Reputation: 0
hello all,

No, I do not think it is possible to use both the cgi sapi and the cli sapi at the same time. If one uses cli sapi then one can not display php pages in a browsers(at least that is what I experienced).

So when i used the cli sapi , i found it difficult to display my php web pages at the same time using apache 1.3 as the webserver. So i have to find another way of executing my script so that it will be able to read from the mysql database as i did while using the php cli sapi (thanks to Bulliver and Nerdstat for their hints ), and then disable the cli so that i will be able to display my other php web pages:

#!/bin/php
mysql_select_db("minedb",$conn);
$irs0=mysql_query("SELECT * FROM shin WHERE dbflag=0",$conn);
$irs1=mysql_query("SELECT * FROM shin WHERE dbflag=1",$conn);
$irs2=mysql_query("SELECT * FROM shin WHERE dbflag=2",$conn);
$irs3=mysql_query("SELECT * FROM shin WHERE dbflag=3",$conn);


while ($irw0=mysql_fetch_array($irs0))
{
ifconfig {$irw0["ifdev"]};
............
.............
}


I was able to realise later that it is actually possible to execute mysql statements in a shell script,even connecting to databases like this:

#!/bin/sh
mysql --user=root --password=ibrotj -h localhost <<!!
mysql_select_db("minedb",$conn);

SELECT VERSION(), CURRENT_DATE;
USE minedb;
SELECT * FROM shin WHERE dbflag=3;
quit
!!

But i find it difficult to find an equivalent statement like the one that retrives data sequentially from mysql database as in the php script like this :

$irw0=mysql_fetch_array($irs3);

while ($irw0=mysql_fetch_array($irs0))
{
ifconfig {$irw0["ifdev"]} ;
..........................
..........................
}

If anybody has done this or has any hints on how to do this , I will be most happy.

Thanks,

Ibro
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Shell Script (with MySql) Tony Empire Programming 1 09-20-2005 09:59 AM
Call a shell script from php? jharper101 Programming 2 02-15-2005 12:51 AM
sendmail won't send from shell or php script dmedici Linux - Software 2 08-24-2004 03:15 PM
PHP pass argument to shell script monzter Programming 2 08-14-2004 06:16 AM
PHP -- How to execute a shell script from PHP using FTP functions?? zoonalex Programming 3 07-29-2004 11:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration