I have a problem running a cronjob. No experience with it, so probably overseeing something nooby. The following script works like a charm (all old filters are deleted from db) when run from the shell:
dude#linux:~> /usr/bin/env /home/dude/RubyOnRails/myproject/script/rails runner /home/dude/RubyOnRails/myproject/script/delete_old_filters.rb
I made the script executable with chmod. Now I want this to run regularly using a cronjob:
dude#linux:~> crontab -e
This file was empty, and I placed this on a single line:
* * * * * /usr/bin/env /home/dude/RubyOnRails/myproject/script/rails runner /home/dude/RubyOnRails/myproject/script/delete_old_filters.rb
I expect the script to run every minute, but nothing happens. In /etc/cron.deny, only 'guest' is mentioned, and /etc/allow does not exist. Restarting my system did not help as well.
The crontab seems to be updated proberly:
dude#linux:~> crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.f9Et2M installed on Thu May 3 14:04:47 2012)
# (Cronie version 4.2)
* * * * * /usr/bin/env /home/dude/RubyOnRails/myproject/script/rails runner /home/dude/RubyOnRails/myproject/script/delete_old_filters.rb
But I expected here a bit as well:
dude#linux:~> atq
dude#linux:~>
The cronjob does something. Every minute an entry is added to /var/log/cron.log:
2012-05-03T15:27:01+02:00 linux /USR/SBIN/CRON[5276]: (dude) CMD (/usr/bin/env /home/dude/RubyOnRails/myproject/script/rails runner /home/dude/RubyOnRails/myproject/script/delete_old_filters.rb)
The problem is, that the job is not executed. It should remove some records from the database, but it doesn't. Running the same script manually does the trick.
Anyone seeing the (perhaps trivial) thing that I missed?
Perhaps this will help, using the brackets.
* * * * * ( colon separated commands-to-execute )
Check it.
Related
I have a script to backup my database at /home/<user>/bin/dbbackup. The script is executable by all users, and owned by me. The files /etc/cron.allow and /etc/cron.deny do not exist.
In my crontab I have the following lines (including a new blank line after the last line of code):
#reboot /home/<user>/.dropbox-dist/dropboxd
30 2 * * * bash /home/<user>/bin/dbbackup
However, cron is not running my dbbackup script. When I run a manual test of the script it works. When I run this test on the command line: * * * * * /bin/echo "cron works" >> ~/file I get the following error:
No command 'dbbackup' found, did you mean:
Command 'dvbackup' from package 'dvbackup' (universe)
Command 'tdbbackup' from package 'tdb-tools' (main)
dbbackup: command not found
My server is running Ubuntu Trusty. Any help please?
As the comments noted, it appears that amiga_os needed remove the reference to bash in the line.
30 2 * * * bash /home/<user>/bin/dbbackup
Should be.
30 2 * * * /home/<user>/bin/dbbackup
I usually just call scripts from their path and use "#!/bin/bash" (or wherever your bash lives) as the first line of the script. It appears the amiga_os had already done this, which is good. I don't like putting sentences into cron because it makes me nervous.
I think it was a path issue as cron executes as the user but does not read the bash profile and therefore does not work exactly like it would under your shell as it might not have access to your $PATH.
I have added a script in crontab for every 30 minutes. The line goes as follows:
*/30 * * * * root perl /root/perl.pl
The above script has a execution of system command 'top' and it gets printed in a log file.
If I run it manually it runs fine. But while running it via crontab, it does not show up the desired results. Please can somebody help me with this. Thank you.
The command in the above perl script is:
$top = `sudo top`;
The error I am getting is:
sudo: sorry, you must have a tty to run sudo
I changed my command from sudo to visudo. But still the problem remains.
You should use the full path in cron (and use which perl to find the full path):
*/30 * * * * root /usr/bin/perl /root/perl.pl
OR better yet, make the script executable using chmod +x, and add the interpreter to the beginning of the script #!/usr/bin/perl -w and call it directly from cron
*/30 * * * * root /root/perl.pl
Also if there is a problem in the perl script, you could output the result from cron like this
*/30 * * * * root /root/perl.pl > /tmp/myscript.log
You should look into the requiretty setting with regard to visudo. Look for a line that reads Defaults requiretty. You could try commenting it out, but you will be sacrificing some security. See man sudoers.
You could also try running top in batch mode with one iteration:
$top = `sudo top -bn1`;
Batch mode option is for sending output to other programs.
I am using ubuntu 12.04.I am using a script(./home/sam/code/imageUpdate) to synchronising images from server to a particular folder in local system. And I have to run the script in the evening always. So I want to write a crontab which will automatically runs the script.
My commands :
$crontab -e;
And added the scheduled time to the crontab file.
# 50 17 * * * cd /home/sam
# 52 17 * * * ./code/imageUpdate > image1.txt
Then I saved the file and waited for the result.
But I didn't get any result. No image was been synchronised to image1.txt file.
Have I left any step ?
Please help me out...
Thanks in advance.
Make sure you don't have hashes (comments) at the start of your crontab commands.
Additionally:
Crontab commands should be run in isolation.
Each crontab command will be run in its own context, changing directory in one instruction probably won't lead to that directory being sound for the next executed (they may be run in their own environments, e.g.).
To overcome this, write a simple shell script which encompasses all of your commands for a single action.
# MyCommand.sh
cd /home/sam
./code/imageUpdate > image1.txt
# crontab command
50 17 * * * /home/sam/MyCommand.sh
i have this crontab,
* * * * * php /etc/raddb/overloaded.php
but it is not running fine, meaning it doesnt run every minute, but when i manually enter this into the terminal (php /etc/raddb/overloaded.php), the script works
thank you guys
PS: im using centos 32 bit. also im using the "crontab -e" to insert and save crontab, but it looks like that crontab is not running? i typed "crontab -e" and yet (* * * * * php /etc/raddb/overloaded.php) appears. where is the issue here? thanks
Crontab syntax is right. Please check if your cron daemon is running and you can check log, maybe it conatins some usefull info.
I think the most possible problem is that cron has its own environment settings. Try to run php with its full path, e.g.
/sbin/php
or w\e path you have
I maintained a database (MySQL), I would like back up some data to the database using a perl script. To save my trouble, I would like cron to do it for me, I inserted the following using crontab
*/5 * * * * blctrl /home/blctrl/code/perl/tt01.pl
However, cron never does its job, any suggestions to get it done? The Linux installed is Centos 5?
*/5 * * * * blctrl /home/blctrl/code/perl/tt01.pl
That looks like the syntax for /etc/crontab, the system-wide crontab file. The first 5 words indicate when to run the command, the 6th is the account under which to run it, and the rest of the line is the command to execute.
(The clue was that the command is under /home/blctrl, which would be the home directory for the account blctrl.)
The syntax for your own crontab, the one you feed to the crontab command, is different. You don't specify an account name, because it only runs under your own account.
Try this:
*/5 * * * * /home/blctrl/code/perl/tt01.pl
EDIT: Incidentally, the first thing I would have tried when encountering a problem like this would be to replace the command with something simple, perhaps touch /tmp/FOO. That would have told you whether the problem was with your Perl script or with your crontab.