Solved

Command for running .php file in ssh

Posted on 2004-09-22
4
653 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
  • 2
  • 2
4 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now