Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Command for running .php file in ssh

Posted on 2004-09-22
4
Medium Priority
?
673 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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

577 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