Reputation: 4267
I am problem scheduling and running a script through cron job. I am on linux (ubuntu), it is a VPS. What I am doing is I have put this line in crontab file that is here: /etc/crontab I wrote:
*/15 * * * * www-data php /var/www/abs/phpscript.php
I have given 777 to the file and after writing above in crontab , I run command:
crontab crontab
Then after almost some time I got the mail in my /var/mail/username file that says: /bin/sh: root: not found
So I am unable to understand what is the problem.
I also run phpinfo and it shows the third variable as APACHE that probably means that PHP is running as apache module.
Please tell what can be the possible solution.
thanks in advance to every one who will try to solve my problem.
Upvotes: 2
Views: 1282
Reputation: 578
You are running a crontab as a user, which means you can't specify the user in the cron.
The template you borrowed your example from was for a system (root) cron.
Remove the username and try again.
Upvotes: 0
Reputation: 742
You can try also to run it using "wget -q -O"
or
*/15 * * * * lynx -dump "url" > /dev/null
Wget examples:
*/15 * * * * wget -O /dev/null 'http://www.mydomain.com/document.php?&user=myuser&password=mypass' >/dev/null
If you need to post data you can use
--post-data "login=user&password=pass"
*/15 * * * * wget -O /dev/null 'http://www.mydomain.com/document.php?&user=myuser&password=mypass' --post-data 'foo=bar' >/dev/null
Upvotes: 4
Reputation: 104020
If you edited /etc/crontab
, you should re-read the warning at the top of the file:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
Running crontab(1)
on the /etc/crontab
file probably contaminated the root user's crontab(5)
file (the one stored in /var/spool/cron/crontabs/
). I suggest running crontab -e
as root to edit the crontab file, and remove all the entries that are identical to the entries from /etc/crontab
. (Maybe you just contaminated your own personal crontab(5)
-- if crontab -e
as root didn't show anything, run crontab -e
under your own personal account and see if the system-wide entries were duplicated into your own crontab(5)
.)
I don't know what file you ran chmod 777
on, but that was probably unnecessary. You really should set your permissions to be as strict as possible to confine the results of malicious attacks or unintentional mistakes.
Upvotes: 2