Solved

Command for running .php file in ssh

Posted on 2004-09-22
4
660 Views
Last Modified: 2010-04-21
Hi:

I have a script .php file which will update the mysql table. Can I run this file in ssh? I tried by run sql_update.php but it say command not found.

Any other command ?

rsdn
0
Comment
Question by:Sohel Rana
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 250 total points
ID: 12121981
Hi rsdn,

make sure that script has execute permissions and specify path to the script

ls -l to determine permissions ... If it does not have execute permissions, use
chmod 0755 filename.php

finally, specify path to the file for execution. e.g. if the file is in current directory, then use ./filename.php ... else specify full path to the file

Sunnycoder
0
 
LVL 16

Author Comment

by:Sohel Rana
ID: 12122085
Hi sunnycoder:

Thanks for your reply. Now the script is executing but it shows error. Although you answer my question but if you can solve it I will increse the points to 500.

Here is the code inside script sql_update.php:

<html>

<head>

</head>
<b>Tableinstaller SQL</b><p>

This program will help you getting exact the same databaselayout that is correct.
This is accomplished by connecting to our server and compare your database with yours. If there is any errors (difference,
either in column size, fieldtype or that the table or field do not exist, this program will try to fix it. It capable of constructing
in a hole databasesite, with primary keys and everything!<p>

Timeout is set to 500 seconds. If you have a special slow connection or slow computer, you can increase the timelimit
inside this script. Or you can download the database structure to your machine to get it correct.

<?

// Set your timelimit below. 500 sek is default
set_time_limit(0);


function update()
{
include "db.php";

$t = 0;

// Where to get the file. If problems, use file('database.txt'); after you have downloaded
// http://domain.com/classifieds/backend/database.txt and put it in the same
// directory as this script.

$content_txt = file('database.txt');


$l = count($content_txt);
$count = 0;

include "config/general.inc.php";


while ($count < $l)
{
      $content_txt[$count] = ereg_replace("category:","$cat_tbl:", $content_txt[$count]);
      $content_txt[$count] = ereg_replace("ad:","$ads_tbl:", $content_txt[$count]);
      $content_txt[$count] = ereg_replace("user:","$usr_tbl:", $content_txt[$count]);
      $content_txt[$count] = ereg_replace("picture:","$pic_tbl:", $content_txt[$count]);
      $content_txt[$count] = ereg_replace("payment:","$payment_tbl:", $content_txt[$count]);
      $content_txt[$count] = ereg_replace("banners:","$banner_tbl:", $content_txt[$count]);
      $content_txt[$count] = ereg_replace("advertisers:","$adv_tbl:", $content_txt[$count]);
      $content_txt[$count] = ereg_replace("favourites:","$fav_tbl:", $content_txt[$count]);
      $content_txt[$count] = ereg_replace("template:","$template_tbl:", $content_txt[$count]);

      //print "Now checking if line $count $content_txt[$count] is present in database...<br>";

      // Loop through "database"

      $result = mysql_list_tables($datab);

      while ($row_table = mysql_fetch_row($result))
      {


            $sql = "SHOW INDEX FROM $row_table[0] FROM $datab";
            //print $sql;
            $result_index = mysql_query($sql);
            $row_index = mysql_fetch_array($result_index);
            $key = $row_index['Column_name'];
            //print "<hr>$sql Indeks er $key<hr>";



            $result3 = mysql_query("SHOW FIELDS FROM $row_table[0] from $datab");
            $i = 0;

            while ($row = mysql_fetch_array($result3))
            {
                   $field = $row['Field'];
                  $type = $row['Type'];


                  if ($field <> $key)
                  {

                        $key_w = "none";
                  }
                  else
                  {
                        $key_w = $key;
                  }


                  $line = $row_table[0] . ":" . $field . ":" . $type . ":" . $key_w . "\r\n";

                  if ($content_txt[$count] == $line)
                  {
                        //print "We have match <br>$content_txt[$count] === $line<p>";
                        $m = 1;

                  }


            }




      }



      // No match!!
      if (!$m)
      {
            list($tablename,$fieldname,$type,$key) = split(":", $content_txt[$count]);



            $key = trim($key);


            $debug = 0;


            // First try to create table
            $sql = "CREATE TABLE `$tablename` (`del` INT);";
            $create = mysql_query($sql);

            if ($create)
            {
                  if ($debug)
                  {
                        print "Table created with $sql<br>";
                  }
            }
            else
            {
                  // Then try to create columns with keys
                  $string = "ALTER TABLE `$tablename` ADD `$fieldname` $type";

                  if ($key <> 'none')
                  {
                        $string = $string . " NOT NULL FIRST;";

                  }

                  $alter_add_field = mysql_query($string);
                  //$alter_add_field2 = mysql_query($string_2);

                  if ($alter_add_field)
                  {
                        if ($debug)
                        {
                              print "Column added with $string<br>";
                        }

                  }
                  else
                  {
                        // Then try just to modify field length and add primary keys


                        $string = "ALTER TABLE `$tablename` ADD PRIMARY KEY(`$key`)";
                        $primary_mod = mysql_query($string);

                        $string_d = "ALTER TABLE `$tablename` CHANGE `$fieldname` `$fieldname` $type DEFAULT '0' NOT NULL AUTO_INCREMENT";
                        $primary_mod_d = mysql_query($string_d);


                        if ($primary_mod)
                        {
                              if ($debug)
                              {
                                    print "Primary key added with $string AND modified with $string_d<br>";
                              }
                        }
                        else
                        {
                              $sql = "ALTER TABLE `$tablename` CHANGE `$fieldname` `$fieldname` $type";
                              $mod = mysql_query($sql);

                              if ($mod)
                              {
                                if ($debug)
                                {
                                    print "Field lengt/type done with with $sql<br>";
                                }
                              }
                        }

                  }

            }





      }

      $m = 0;

      print "<p><p>";
      // next field
      $count++;

}


if ($error)
{
      print "This program needs to be run again to do more changes. Just hit the REFRESH button in your browser.";
      $error = 0;
}
mysql_free_result($result);
}

while ($teller < 4)
{
      $teller++;
      if ($debug)
      {
      print "<hr>Run $teller:<p>";
      }
      update();
      if ($debug)
      {
      print "</hr>";
      }


}

?>

---------
rsdn
0
 
LVL 16

Author Comment

by:Sohel Rana
ID: 12122119
oh sorry forget to tell the error :

It says :

/home/sara/public_html/sara/admin/sql_update.php: line 1: syntax error near unexpected token 'newline'

rsdn
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12130881
I am not too familiar with php ... but here is a guess
start your script with
#!/usr/bin/php -q
<?php

php TA might be a better place to ask this
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question