I would like to know how to make a cronjob every 5 minutes ?
I found on Internet that I have to do */5 * * * * but the problem is when I try this I am facing this error
Where is the problem ?
Thank you !
It can be several things:
there are an unwanted control characters in file (you can check with cat -v /etc/crontab or cat -v /var/spool/cron/crontabs/username if this is user crontab entry). Cron daemon has very sensitive parser and unwanted non-printable characters cause errors.
there are empty variable assignments above/under the line erroring (such as MAILTO=)
this is the last line in file and it does not end with newline character. Some implementations of cron (you don't state anything beyond "Debian" tag) require first and last line to NOT be crontab entries.
you have very old cron implementation that doesn't support such */n syntax (afaik Solaris and older busybox cron daemons don't). In that case you need to use workaround and list all 5 minute milestones within one hour like this 0,5,10,15,20,25,30,35,40,45,50,55 * * * * command as a workaround.
It would help if you post a minimal reproducible example of crontab file that errors and version of cron daemon you are using.
Related
I had one cronjob:
*/10 * * * ruby /home/pi/GIT/Zonky/Ruby/getUserLoans.rb
Everything worked just fine.
I added a second one:
*/5 * * * python /home/pi/Crypto/Crypto_cron.py
Since the edit, cron doesn't do any of the two jobs.
I used the following command:
cat /var/log/syslog | grep -i CRON
On the attached screenshot please note:
last cron run of ruby command at 7AM
Editing crontab for the first time at 7:05
No ruby nor python command since then
I also restarted cron daemon, which didn't help.
I have no idea where to look for an answer.
Thank you
My problem was the existing command.
It worked for months - which gave me the confidence that it is correct, while it was correct
I use vim and probably due to some reckless use of hotkeys I managed to broke the existing command. That's the issue here.
So both commands are wrong, there should be 5 time parameters (e.g. stars) and I only have 4.
I want to run a crontab every 15minutes. I tried this:
0 */15 * * * ./usr/My_PATH/run.sh
But I get this error:
0 command not found
Is there something wrong with the syntax ?
Many thanks.
UPDATE:
I corrected the script and I tried this:
*/15 * * * * /My_Path/run.sh
and this
0,15,30,45 * * * * /My_Path/run.sh
In both cases I get an error.
#1 bash: */15: No such file or directory
#2 bash: 0,15,30,45 command not found
If this:
0 */15 * * * ./usr/My_PATH/run.sh
fails with this error:
0 command not found
then you're trying to run it as a shell command. You need to feed it to the crontab command. There are several ways to do this.
crontab -l will list the current contents of your crontab; it doesn't modify it.
crontab -e will open (a copy of) your crontab in a text editor and let you modify it. This is probably the simplest way to update it.
crontab filename reads the specified file and replaces your current crontab with its contents. (If you already have a crontab, this will quietly clobber it.)
The method I recommend is to keep a separate file containing your crontab (say, crontab.txt).
First, if you already have a non-empty crontab (check with crontab -l), save it to the file:
crontab -l > crontab.txt
Make whatever additions or other changes you want to that file, and then use
crontab crontab.txt
to install the updated crontab.
You can keep backup copies (I maintain mine in a source control system) so you can recover if you mess something up. And you can do a quick crontab -e if you want to test something, then re-run crontab crontab.txt to revert to the stored crontab.
The syntax of the crontab line in your question:
0 */15 * * * ./usr/My_PATH/run.sh
is correct, but the path ./usr/My_PATH/run.sh looks like it may be incorrect. Cron jobs run from your home directory, so the path is valid only if the usr directory is directly under your home directory (and in that case the ./ is unnecessary). It's probably better to specify the full path, which can start with $HOME/.
Yes.
First field is minutes. Second field is hours. You're setting it off at zero minutes past the hour, every 15th hour. So basically - 15:00 each day.
You want:
*/15 * * * * /some_script
Furthermore - ./ - it's a relative path, and that's probably a bad idea with cron, because it doesn't chdir to run stuff. Use an absolute path to avoid confusion. If you absolutely need to be in a particular directory for the script to work, you can try:
cd /path/to/script && ./this_script
So it's quite possible that you've got broken permissions or just not finding a relative path that you're using.
A script start.sh is registered in crontab to run on daily basis
But I'd like to save the output of the program to a file, like cronlog-yyyyMMdd.log
I tried the following but failed:
16 10 * * 1-5 ~/start.sh >> ~/cronlog/$(date+"\%F")-cron.log 2>&1
Anyone help me?
Using fully-qualified paths to all programs and files that are mentioned eliminate a whole class of errors from debugging issues with crontab entries. In this particular case, doing so would have only proved there were no problems with PATH issues in your crontab entry.
Your issue is that you need a space char between the date cmd and it's formatting argument string, instead of
$(date+"\%F")
#0 ^v
$(date +"\%F")
I commend you for your good crontab debug etiquette; capturing std-err and std-out to a file gives you 1. proof that your command ran when you expected it to (or if you have an error in your time specification, it will show you when the cmd did run). 2. you avoid having your localhost email box filling up with msgs from the cron daemon. 3 Any std-err msgs that were generated are also captured and are in generally in sync and time order with std-out messages.
IHTH.
16 10 * * 1-5 ~/start.sh >> ~/cronlog/$(date +"\%F")-cron.log
Edit: as explained in comments, this answers the question by correcting a typo in the asker's attempted entry
this is my first time writing script for cron job.
I wrote my code in shell, (which it works) and I'm trying to set it up for cron.
So here is my question. How do I set up the cron? Am I suppose to write
10 * * * * /home/workstation/deleter.sh (I want it to run every 10min)
right underneath #!/bin/sh? How would I execute it? (deleter.sh has permission via chmod)
man 1 crontab returns "No entry for crontab in section 1 of the manual"
I'm really lost and confused right now. If someone know how to set up cron please tell me!!
Thanks in advance
#!/bin/sh
counter=0
logloc=/home/ServerLogs
backup=/home/test
## Reads the location of the file systems that needs to be investigated from location.txt
## and save it into an array
while read -r line; do
Unix_Array[${counter}]=$line;
let counter=counter+1;
done < location.txt
## Reads Email recipients and save it into an array
More code continues from here......
The following will open your environment's text editor and load the crontab:
crontab -e
Your crontab entry is mostly correct. In order for your script to run every ten minutes it should be changed to:
*/10 * * * * /home/workstation/deleter.sh
The entry you indicated would run the script at the 10th minute of every hour.
To setup the cron, you can do one of two (main) things. The first would be to place the specified line in /etc/crontab. The second would be to run crontab -e and place the line in there. I would recommend to use crontab -e so the cron will execute as your own user account.
If the full path to the script is /home/workstation/deleter.sh and it does have execute-privileges, as you specified - your current line will have it execute 10-minutes past the hour, every hour. To get it to execute every 10 minutes, you'll have to use */10, like this:
*/10 * * * * /home/workstation/deleter.sh
this might help
http://www.manpagez.com/man/5/crontab/
you need to get an entry into your crontab
One of the best links I came across when I first learned about cron! Bookmark it
http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/
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.