Crontab not working in Ubuntu 10.04
Solution 1
There are three different ways to use cron.
- 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
Solution 2
Just to be sure:
crontab -e
then
30 21 * * * /home/john/Desktop/test.sh
EDIT: I mean that you don't need no "john" beside the time section of cron and the path to the command.
Solution 3
* * * * * john /home/john/Desktop/test.sh
The "john" here is wrong. Only the system crontab has a user name field; the per-user crontabs which you edit with crontab -e do not have it (the user is implicit). Just leave it out.
Also, if I need to run some commands as root I'm supposed to use it with crontab -e -u right?
No, if you want a cronjob to run with root rights just do
sudo crontab -e
(or put it into the system crontab, with user name "root").
Related videos on Youtube
john p
Updated on September 17, 2022Comments
-
john p over 1 year
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/cronjobHave done a
chmod 777 test.sh
and can run it. Listing it shows as rwx for users/group/global. Then I do acrontab -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
? -
Satanicpuppy over 13 years@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.
-
Mr2468601 about 11 yearsThere's also the
/etc/cron.d
you didn't mention.