Centos – crontab command says permission denied

centoscronPHP

I am working on cent-OS server. I have two scripts to run by cron. Scripts are in PHP and i have a Apache module of PHP installed on cent-OS. One Script should run everyday at 6pm and other on every Thursday. My cron commands are:

00 18 * * * lynx -dump http://domain/folder1/script1.php //every Day

00 02 * * 5 lynx -dump http://domain/folder1/script2.php //every Thursday at 2am

i wrote both the lines in my /etc/crontab file and tried to execute it from

[root@domain ~]# /etc/crontab crontab
-bash: /etc/crontab: Permission denied

Searched online but no solutions. Any ideas what i am missing?

Best Answer

crontab is not an executable file. It is used by cron to know when the jobs should be scheduled.

/etc/crontab is not executable (hence the error)

Your crontab file is invalid (comments in C or Java style ere not allowed):

from the man page:

Lines whose first non-space character is a pound-sign (#) are comments, and are ignored. Note that comments are not allowed on the same line as cron commands, since they will be taken to be part of the command. Similarly, comments are not allowed on the same line as environment variable settings.

You should write something like:

# every day
0 18 * * * lynx -dump http://domain/folder1/script1.php > /tmp/somefilename

Notice that lynx -dump will just print the page to standard output. If you want to store it somewhere you need to redirect the output to a file (see example)

To see if it works wait until 00:18 or use a time nearer in the future for testing purposes

Related Topic