Solved

Command for running .php file in ssh

Posted on 2004-09-22
4
654 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
llcommand 6 87
What are recommended OS for exim mail server? 10 101
Sed question 2 68
ipconfig not working on windows 10 bash shell; what other commands are missing. 17 120
Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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.
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.

910 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

17 Experts available now in Live!

Get 1:1 Help Now