I installed it in a machine at work and it wouldn't do anything, no matter what I did. So now I have it on virtualbox at home and it also doesn't work. Here's what I'm trying to do:

Have a file on /home/john/Desktop called test.sh. Its contents:

#!/bin/bash
echo "Bing!" > /tmp/cronjob

Have done a chmod 777 test.sh and can run it. Listing it shows as rwx for users/group/global. Then I do a crontab -e and add the following line:

* * * * * john /home/john/Desktop/test.sh

But it doesn't work. The file is never written. I've also tried using a specific time (for example, it's 9 PM so I set the hour to 05 21 and wait) but it doesn't work as well. I've also tried without the user "john" in the crontab but no dice. I tried using crontab -e -u john too. Nothing works.

Doing a service cron status I get that it is started/running. I've tried restarting it as well.

What am I doing wrong?

Also, if I need to run some commands as root I'm supposed to use it with crontab -e -u <username> right?

Putting scripts in the /etc/cron.hourly , /etc/cron.daily , /etc/cron.weekly or /etc/cron.monthly folders
The system will then run those at the scheduled time with root privileges

Editing /etc/crontab
This takes a syntax like the one you were trying to use in crontab -e, because here you can specify which user should be responsible for the scheduled job, in your case, john.

The crontab command, which saves a cron tab for the user that made the job in /var/spool/cron/crontabs

If you are using the third method, you don't need to tell it you are john, it already knows. You can however tell it with the -u flag to save the job in someone elses cron tab.
Using the third method, you do not need to have the john in * * * * * john /home/john/Desktop/test.sh

system crontab? could you explain? would it be right to use crontab -e -u root?
–
john pJul 30 '10 at 0:41

1

@john p: Yes, and no. If you've editing the files in /etc/cron.whatever, then YES, you need a user name. If you're logged in as john, and editing your default crontab with crontab -e, then NO, you don't need a username.
–
SatanicpuppyJul 30 '10 at 3:04