1
votes

I have an email parsing script on a Codeigniter site that I want to trigger each day with a cronjob. I don't have much experience with cronjobs, or command line on remote servers.

I have a cronJobs controller at mysite.com/public_html/application/controllers/cronJobs. In it is a parseMail method. I'm also using mod_rewrite to get rid of index.php from URLS.

The parseMail method does work when I hit the controller "normally" through my browser at MYSITE.com/cronJobs/parseMail. There is a DB insert that goes off.

But to trigger it with cronjob I have tried >>>

wget http://MYSITE.com/cronJobs/parseMail

And I do get a notification email.. but I'm not sure how to interpret it. It's finding the script? There is no error? Regardless, the parseMail doesn't fire.

--2013-01-19 12:00:02-- http://MYSITE.com/cronJobs/parseMail
Resolving MYSITE.com... xx.xx.xx.xxx
Connecting to MYSITE.com|xx.xx.xx.xxx|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 0 [text/html]
Saving to: `parseMail.203'

0K 0.00 =0s

2013-01-19 12:00:03 (0.00 B/s) - `parseMail.203' saved [0/0]

I also tried

-q wget http://MYSITE.com/cronJobs/parseMail

And received "/bin/sh: get: command not found"

Then I have also tried variations on this..

/usr/local/bin/php -q /public_html/index.php cronJobs parseMail
/usr/local/bin/php -q /public_html/ cronJobs parseMail
/usr/local/bin/php -q home/myusername/public_html/index.php cronJobs parseMail
/usr/local/bin/php -q home/myusername/public_html/ cronJobs parseMail

With these methods I cant even seem to hit the controller. My email notification just says "Could not open input file".

I'm just not really familiar with any of these errors.. so I don't know how to hone in on a solution.

Can anyone give me any tips how to move forward?

2

2 Answers

3
votes

solved

After much Googling I found the solution that worked for me. Here is what I used (I was so close in one of my first attempts.. just didn't use an absolute path. And then when I started using some of the suggestions from the comments below, the php path was different and I did not notice)

Here is the correct version.

/usr/local/bin/php /home/myusername/public_html/index.php cronJobs parseMail
1
votes

None of your paths are real path. All are either invalid (/public_html ones) or relative (home/myusername ones). Following should do.

/usr/bin/env php  /home/myusername/public_html/index.php cronJobs parseMail

You might need to change the directory to document root first. In that case use this,

(cd /home/myusername/public_html/ &&  /usr/bin/env php index.php cronJobs parseMail)