We help IT Professionals succeed at work.

Crontab Problem

tripat
tripat asked
on
Hi,

I am trying to add a file to crontab so that it executes the cronemail.php every minute. But after adding the file in crontab and running command:
shell> crontab crontab

it gives me error worng minute on line no 6.

Below is the format of crontab file:

--------------------
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

* * * * * lynx -dump
http://www.greatpresence.com/~massemail/massemail2/cronemail.php

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

# Monitor services to make sure everything is still okay.
0,15,30,45 * * * * root /usr/local/sbin/swatch >>/var/coballt/adm.log 2>&1

---------------------------

I have added the line
* * * * * lynx -dump
http://www.greatpresence.com/~massemail/massemail2/cronemail.php

Also, I am confused and want to know how can I check if php is installed as cgi or Apache module.

Regards,
Tripat

Comment
Watch Question

Commented:
the crontab should look that


* * * * * lynx -dump  http://www.greatpresence.com/~massemail/massemail2/cronemail.php
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
# Monitor services to make sure everything is still okay.
0,15,30,45 * * * * root /usr/local/sbin/swatch >>/var/coballt/adm.log 2>&1


be careful you must have a blank line after your last line

You cannot put variables into a crontab file

Author

Commented:
Dear us111,

But if I remove the line

* * * * * lynx -dump  http://www.greatpresence.com/~massemail/massemail2/cronemail.php

it functions correctly.

Also how can I judge if PHP is installed as cgi or as a Apache Module?

thanx for ur help.

Regards,
Tripat


Commented:
Your key line should read
     */1 * * * * lynx -dump ...
assuming that the rest of the command works properly from the commandline.  Once again, that's "*/1" as in all minutes divisible by one. Every five minutes would be "*/5".

As for judging if PHP is installed as a cgi or as a module, this is irrelevant to the above command working.  However... If you specifically start your php scripts with a line similar to:
     #!/usr/local/bin/php
or if you access pages via http://server.com/cgi-bin/php.cgi
you are using PHP as a cgi. Otherwise, you are using PHP as a module.

Commented:
-to know if Apache is installed as a module : goto httpd.conf and check for php....so or libphp4.so in the LoadModule directive

-to know if you have php as cgi-bin, have a look at /path/toapache/cgi-bin

or try to find a folder bin where php coul be installed:
# find / -name php -print



Author

Commented:
Thanx for comments,

Now, I know that on my server php is not installed as cgi-bin.

Also, I have checked my command

lynx -dump http://www.greatpresence.com/~massemail/massemail2/cronemail.php

on command line and it runs ok.

Now, I have created a ew file of crontab which only have one command in it that is

* * * * * lynx -dump http://www.greatpresence.com/~massemail/massemail2/cronemail.php 

but still I get error of bad minute at line 1.

I have left one empty line in the end of file too.

pls help.

Regards,
Tripat

Commented:
sure you cannot have * * * * *
as loganh said, try */1 * * * * instead

if you'd like to have php as cgi-bin you can install it,
./configure --prefix=/usr/local/php
for example

The default compilation installs php as cgi-bin but don't use it with your webserver

http://www.greatpresence.com/~massemail/massemail2/cronemail.php is not really secured becauce I can access the URL.

Author

Commented:
yes, I have tried */1 too but same error.

Tripat

Commented:
try the full path to linx

Author

Commented:
Hi us111,

I have still modified it to:

01 * * * * /usr/bin/lynx -dump
http://www.greatpresence.com/~massemail/massemail2/cronemail.php

I know in start "01" will not solve my purpose(it will be hourly) but still it is giving me bad minute error.

Regards,
Tripat

Commented:
so you'd like to run your script every hours ??

Author

Commented:
I want to run my script every minute or 2 minute but it is not working out so for just trying purpose I have kept it 01.

Tripat

Author

Commented:
Hi,

I have by hit and trial found that error was coming as the url of script to run was long and coming in second line, when I have reduced the url to

http://http://www.greatpresence.com/~massemail/1.php it works fine as full line now fits on single line.

But still the script is not running as I did not receive the mail it is sending.

How can I judge now where is the problem?

Regards,
Tripat



Commented:
hmm
first you should install php as cgi-bin rather than using lynx.

It will be better to detect the problem
and in your

1* * * * /pathtophp/bin/php -f /pathtoyourscript/cronemail.php

and you can test it without the webserver

time to leave, see you tomorrow

Commented:
In the system crontab file you must specifiy a user name between the time fields and the command field:

1* * * * USERNAME /usr/bin/lynx -dump http://www.greatpresence.com/~massemail/massemail2/cronemail.php



Commented:
sorry it took me a while trip@
look under /etc/cron.daily and you will see a file called "0anacron" copy that file, or just view it
to understand why it should be there.  copy this file to /etc/cron.minutes and see it run.

Author

Commented:
thanx, the problem is solved

Explore More ContentExplore courses, solutions, and other research materials related to this topic.