10 Replies - 539 Views - Last Post: 24 February 2012 - 04:07 AM Rate Topic: -----

#1 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

[SOLVED][SSH] Raising False Script Error

Posted 23 February 2012 - 04:57 AM

Fix
I managed to get it working. The entire thing wasn't working because my CRON.php contained a class. Because I included functions.php, that had linkage to other classes so I had to dump functions.php and only carry the functions that I needed inside the CRON.php. Not the best service 1and1 could offer, but it's working now.

Thanks to those who offered help, it's greatly appreciated.

~huzi



Good morning.

I am trying to set a CRON job to back-up my database at a regular interval. My PHP script checks to see if a back-up is required, regardless of the regular interval.

Now, when I view the page in my browser, it works perfectly; it tells me that no back-up is required. However, when I try to parse the file via SSH, it brings: Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /homepages/7/d404100790/htdocs/Work/CRON.php on line 14

The page: http://www.mhprogram....co.uk/CRON.php

The PHP script:

<?php

/**
 * @author MHProgramming
 * @copyright 2012
 */

include "functions.php";

mail("*****", "From CRON", "File Accessed.", phpversion());

Class BackUp
{ //THIS IS LINE 14
    
    public function Run()
    {
        $filename = 'DIRECTORY_HIDDEN/BACK_UO_FILENAME_HIDDEN';
        
        if ( file_exists ( $filename ) )
        {
            echo "No Back-up required.<br />";
            mail("******", "From CRON", "It worked.", phpversion());
        }
        else
        {
            echo "Running back-up...<br />";
            $this->DoBackUp();
        }
    }
    private function DoBackUp($tables = '*')
    {      
        //BACK-UP CODE
    }
}

$maintanence = new BackUp;
$maintanence->Run();
?>



There is no error, but SSH believes there is..

I hope help is on the way, 'cause I'm pulling my hair out.

Thanks in advanced.


~huzi

MOD EDIT: Removed email address

This post has been edited by huzi8t9: 23 February 2012 - 11:06 AM


Is This A Good Question/Topic? 0
  • +

Replies To: [SOLVED][SSH] Raising False Script Error

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,437
  • Joined: 23-August 08

Re: [SOLVED][SSH] Raising False Script Error

Posted 23 February 2012 - 05:17 AM

I don't usually capitalize Class, but not sure that's the issue.

My guess is it has to do with the include path, where you're using an included file. The include path for the shell-executed script is likely different from the webserver's include path.
Was This Post Helpful? 0
  • +
  • -

#3 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

Re: [SOLVED][SSH] Raising False Script Error

Posted 23 February 2012 - 05:28 AM

View PostJackOfAllTrades, on 23 February 2012 - 12:17 PM, said:

I don't usually capitalize Class, but not sure that's the issue.

My guess is it has to do with the include path, where you're using an included file. The include path for the shell-executed script is likely different from the webserver's include path.


It says nothing about the include though, surely I'd get "Warning: include(functions.php) [function.include]: failed to open stream: No such file or directory in /homepages/7/d404100790/htdocs/Work/CRON.php on line 8"?

Although, when setting up my CRON job, I was informed that I should receive an e-mail to confirm my CRON job - I haven't...

Here's my CRON job:

# Edit this file to introduce tasks to be run by cron.
* * * * * /usr/bin/php /homepages/7/d404100790/htdocs/Work/CRON.php
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command



Thanks for your reply

~huzi
Was This Post Helpful? 0
  • +
  • -

#4 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: [SOLVED][SSH] Raising False Script Error

Posted 23 February 2012 - 06:27 AM

What exactly are you doing to run this script via SSH?

What are the contents of functions.php?

Have you checked the contents of the file on the server that you're trying to access directly?
Was This Post Helpful? 0
  • +
  • -

#5 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

Re: [SOLVED][SSH] Raising False Script Error

Posted 23 February 2012 - 08:20 AM

What exactly are you doing to run this script via SSH?

Using third-party software, PuTTY, I'm connecting to my host (mhprogramming.co.uk)
Attached Image
... to create a CRON job, and the only way is through SSH. So I'm loading up PuTTY, I fill in my host name, username and password.
Attached Image
Then I type "crontab -e" which loads my bash file for editing.
Attached Image
Once I've edited appropriately
Attached Image
... I'm hitting ESC then typing ":x" to save
Attached Image

What are the contents of functions.php?

In the £functions.php," I have a small collection of functions for interacting with my database - connectivity and querying and such. This file is used throughout my entire website.

Have you checked the contents of the file on the server that you're trying to access directly?
Yes I have - you may do so to here. When accessed through a browser, no errors are displayed and none saved into the error log on my server.

I hope I've been thorough enough.

Thank you for your reply.

~huzi

This post has been edited by huzi8t9: 23 February 2012 - 09:58 AM

Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,437
  • Joined: 23-August 08

Re: [SOLVED][SSH] Raising False Script Error

Posted 23 February 2012 - 09:05 AM

What happens if you try to run the script from within the shell? That might provide some helpful info. Run it just as the cron job is setup.
Was This Post Helpful? 1
  • +
  • -

#7 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

Re: [SOLVED][SSH] Raising False Script Error

Posted 23 February 2012 - 09:10 AM

View PostJackOfAllTrades, on 23 February 2012 - 04:05 PM, said:

What happens if you try to run the script from within the shell? That might provide some helpful info. Run it just as the cron job is setup.


That's where I get my parse error.

Attached Image
Attached Image

Thank you for your reply.

~huzi

This post has been edited by huzi8t9: 23 February 2012 - 09:19 AM

Was This Post Helpful? 0
  • +
  • -

#8 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: [SOLVED][SSH] Raising False Script Error

Posted 23 February 2012 - 09:56 AM

Wow, what is with the blurring, anyway....

Is your website root in /Work? If not, how does htdocs/CRON.php (with htdocs as the assumed webroot) point to htdocs/Work/CRON.php (actual root). Do cat -n Work/CRON.php once you've logged on, and see if there's anything obvious.

This post has been edited by RudiVisser: 23 February 2012 - 09:57 AM

Was This Post Helpful? 0
  • +
  • -

#9 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

Re: [SOLVED][SSH] Raising False Script Error

Posted 23 February 2012 - 10:01 AM

View PostRudiVisser, on 23 February 2012 - 04:56 PM, said:

Wow, what is with the blurring, anyway....

Is your website root in /Work? If not, how does htdocs/CRON.php (with htdocs as the assumed webroot) point to htdocs/Work/CRON.php (actual root). Do cat -n Work/CRON.php once you've logged on, and see if there's anything obvious.



Sorry for the blurring, concealing my code.

mhprogramming.co.uk points to ROOT/Work/. When I ran cat -n Work/CRON.php, it just basically gave me back all my code inside the console.

The raised error claims that there's an error on line 14. Line 14 is "public function Run()"

Thanks for your reply

~huzi

This post has been edited by huzi8t9: 23 February 2012 - 10:04 AM

Was This Post Helpful? 0
  • +
  • -

#10 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: [SOLVED][SSH] Raising False Script Error

Posted 23 February 2012 - 12:56 PM

View Posthuzi8t9, on 23 February 2012 - 05:01 PM, said:

mhprogramming.co.uk points to ROOT/Work/. When I ran cat -n Work/CRON.php, it just basically gave me back all my code inside the console.

The raised error claims that there's an error on line 14. Line 14 is "public function Run()"

Yes, this is the point. It was to confirm that the script is correct on the server as it is on your site, but if it's pointing to htdocs/Work then it's correct.

If you post Line 11/12/13/14/15/16 here (from that cat output) then we can maybe help further, but it's pretty weird.
Was This Post Helpful? 0
  • +
  • -

#11 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

Re: [SOLVED][SSH] Raising False Script Error

Posted 24 February 2012 - 04:07 AM

View PostRudiVisser, on 23 February 2012 - 07:56 PM, said:

View Posthuzi8t9, on 23 February 2012 - 05:01 PM, said:

mhprogramming.co.uk points to ROOT/Work/. When I ran cat -n Work/CRON.php, it just basically gave me back all my code inside the console.

The raised error claims that there's an error on line 14. Line 14 is "public function Run()"

Yes, this is the point. It was to confirm that the script is correct on the server as it is on your site, but if it's pointing to htdocs/Work then it's correct.

If you post Line 11/12/13/14/15/16 here (from that cat output) then we can maybe help further, but it's pretty weird.


I've managed to get it working now. It didn't work because my script contained a class... see my first post for the full details.

Thank you for your reply

~huzi
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1