Server Configuration & Security > PHP Installation and Configuration
Script error "Command not found"
(1/1)
Ne0Geek:
I am using Amazon Web Services to run a virtual machine with a Centos image. This machine is a dedicated MySQl server. I am using php script to backup my databases. I am running php in terminal. The script is generating errors that are beyond my scope of knowledge. I desperately need help.
--- PHP Code: ---<?php
$emailaddress = "email.domain.com";
$host = "INTERNAL_IP"; // database host
$dbuser = "db_id"; // database user name
$dbpswd = "db_pswd "; // database password
$mysqldb = "schema"; // name of database
$path = "/home/ec2-user/Backup"; // full server path to backup files directory
// backup database & Compress backup files
$filename = "/home/ec2-user/Backup" . $day . ".sql.gz";
if ( file_exists($filename) ) unlink($filename);
system("/usr/bin/mysqldump --user=$dbuser --password=$dbpswd --host=$host $mysqldb > $filename",$result);
//formate file sizes
$size = filesize($filename);
switch ($size) {
case ($size>=1048576): $size = round($size/1048576) . " MB"; break;
case ($size>=1024): $size = round($size/1024) . " KB"; break;
default: $size = $size . " bytes"; break;
}
//Backup complete messages
$message = "The database backup for " . $mysqldb . " has been run.\n\n";
$message .= "The return code was: " . $result . "\n\n";
$message .= "The file path is: " . $filename . "\n\n";
$message .= "Size of the backup: " . $size . "\n\n";
$message .= "Server time of the backup: " . date(" F d h:ia") . "\n\n";
mail($emailaddress, "Database Backup Message" , $message, "From: Website <>");
?>
--- End code ---
Results:
: No such file or directory?php
./SD_DBbackup.php: line 2: =: command not found
: command not foundline 2:
./SD_DBbackup.php: line 3: =: command not found
./SD_DBbackup.php: line 3: //: is a directory
./SD_DBbackup.php: line 4: =: command not found
./SD_DBbackup.php: line 4: //: is a directory
./SD_DBbackup.php: line 5: =: command not found
./SD_DBbackup.php: line 5: //: is a directory
./SD_DBbackup.php: line 6: =: command not found
./SD_DBbackup.php: line 6: //: is a directory
./SD_DBbackup.php: line 7: =: command not found
./SD_DBbackup.php: line 7: //: is a directory
./SD_DBbackup.php: line 8: //: is a directory
./SD_DBbackup.php: line 8: Compress: command not found
./SD_DBbackup.php: line 9: =: command not found
./SD_DBbackup.php: line 9:
./SD_DBbackup.php: line 10: syntax error near unexpected token `$filename'
./SD_DBbackup.php: line 10: `if (file_exists($filename) ) unlink($filename);
ErnieAlex:
Well, you create a file name based on $day, but, never set $day.
Not sure but, that might be the issue. Let us know...
Ne0Geek:
Than you all for your great suggestion. I very much appreciate it. I was able to run the this script successfully. The problem was generated, I think, due to not including the php line interpreter flag to invoke the terminal.
This topic can be closed, thanks again for the help.
ErnieAlex:
Glad you sorted it all out! CYA in the bitstream...
Navigation
[0] Message Index
Go to full version