I have set a crontab for a PHP script, which executes itself with no issues. My question is about the crontab; currently, I have this:
30,* 11 * * * php /Users/username/script.php >>/Users/username/script.log 2>/Users/username/script-error.log
With this crontab, I would expect the execution of the script every minute within 11:30 and 11:59.
Instead, the script is being executed every minute within 11:00 and 11:59.
How can I set a crontab that allows me to run the script every minute within 11:30 an 11:59?
Thanks
The comma in 30,* acts as a separator for two values: the first value 30 and the second value *. As the second value (*) matches every minute, the script is executed every minute.
What you want is a range, which you could specify with 30-59:
30-59 11 * * * php /Users/username/script.php >>/Users/username/script.log 2>/Users/username/script-error.log
Related
I have many Command class and they are running in background in my Laravel project.
I have a scenario and I want to run one of the after another one.
$schedule->command('mycommand:first')->cron("*/40 * * * *")->withoutOverlapping();
$schedule->command('mycommand:two')->cron("*/40 * * * *")->withoutOverlapping();
they are running every 40 minutes. but I want to run Command two 10 minutes after Command first.
How can I do that?
If you just want to start command 10 minutes after the first command, you have to set properly cron command. So for your example it would be:
$schedule->command('mycommand:first')->cron("*/40 * * * *")->withoutOverlapping();
$schedule->command('mycommand:two')->cron("*/50 * * * *")->withoutOverlapping();
If you want to learn more about those cron settings you can try something like crontab.guru
If you want to run mycommand:two 10 minutes after mycommand:first finished, you have to probably edit mycommand:first to set some timeout and execution of mycommand:second at the end of the command.
*/10 * * * * /bin/sh /dataScience/dat/JOB/forker.sh
Above is the cron job which does not execute. I have checked separately both the functioning of cron job and shell script which works fine. Even the below command works well.
/bin/sh /dataScience/dat/JOB/forker.sh
I have also checked the permissions of forker.sh which shows
-rwxr-xr-x 1 mango wheel 442 Nov 20 12:53 forker.sh
Am i missing something which restricts the cron job from triggering the script?
Generally the syntax for the job goes like:
minute hour dom month dow user cmd
In your case, the job might be for multiple user, it seems
*/10 * * * * /bin/sh /dataScience/dat/JOB/forker.sh
Which implies it should be run at the interval of 10 mins all the time. Which is not problematic.
Can you tell us if the following is giving you the output at all?
*/10 * * * * (echo "Printing."; echo "Logging." > /dataScience/dat/JOB/abc.txt | mail -s "Mailing" your_email)
Note: I wanted to comment this, since this is not exactly the answer but debugging, but I have reputation lesser than 50, hence couldn't comment.
I have gone through all sorts of answers and replies up and down the Internet and nothing to seem to work for me. I want to simply run a bash script every minute using CRONTAB on Raspberry PI on Raspbian.
I have a script called autocon.sh and I simply entered into crontab as follows:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
...
1 * * * * root bash /home/pi/autocon.sh
BUT IT WON'T RUN.
What am I doing wrong?
I'm not sure where the 'root' part comes from, but I'm guessing you're wanting to run the script as root? If so, you need to put an entry into the root crontab, do so by running:
sudo crontab -e
This will open up the root user crontab for editing, anything run from said location will run with root priveleges.
Insert the following line:
* * * * * bash /home/pi/autocon.sh
That should do it :) The 1 in your script actually means 'run at 1 minute past the hour' and thus in your case, 1 minute past every hour - easy mistake! Replacing it with a * means every minute.
The syntax is:
minute - hour - day of month - month - day of week - command
Additionally, if you make your script executable, like so:
sudo chmod +x /home/pi/autocon.sh
You can omit the 'bash' command, and simply use:
* * * * * /home/pi/autocon.sh
And unless you're using the two lines at the top for something in particular, you can omit those too.
For clarity, Barmar's comment on my original post:
In per-user crontab files you don't put the username. But in
/etc/crontab you do.
To run a cronjob every minute, all the values must be stars. Your cronjob is set to run at 1 minute past the hour every hour.
It should be:
* * * * * root bash /home/pi/autocon.sh
I understand I can set a cron job to run every 5 minutes with crontab -e by adding a line such as: */5 * * * * /path/to/script.sh.
Is it possible to get the system time in minutes using date +"%M" for example, and then set a cron job to run at date +"%M" plus 5 minutes?
I know I can get date +"%M" + 5 via the following process:
$ MIN=`date +"%M"`
$ export MIN
$ expr $MIN + 5
Is it possible to use this to set a cron job or script to run at "current time in minutes" plus "X minutes"?
I could imagine this being useful in an application in which a user creates a new document and then is prompted to save or title the document X minutes after creating it.
You should use the at command instead.
With at, you can specify the time when a command should be run using time or even keywords like midnight, teatime, tomorrow etc..
You can specify the time after 5 min like this:
at now + 5 min
And then enter the command you want to schedule. Or you can enter your scheduled jobs in a jobs file and give it as a argument for the at command using the -f option.
Sample of a jobs file:
$ cat myjobs.txt
/path/to/a/shell-script.sh
/path/to/any/command/or/script.sh
The following command will execute those jobs after 5 mins:
$ at -f myjobs.txt now + 5 min
Check this link for more information.
Look at the at command. Maybe this is what you are looking for.
See
http://www.computerhope.com/unix/uat.htm
http://www.thegeekstuff.com/2010/06/at-atq-atrm-batch-command-examples
Yes you can:
*/5 * * * * /path/to/script.sh && crontab -r
I'm new to cron jobs. I read a post on how to write a cron job with crontab.
So my crontab looks like this:
1 * * * * /Users/apple/Desktop/wget/down.sh
which basically means that every minute i want to execute the script :down.sh. Now the script runs
fine manually. The script is a simple program that downloads a PDF from the internet:
#!/bin/bash
wget -U Mozilla -t 1 -nd -A pdf "http://www.fi.usj.edu.lb/images/stories/HoraireS08/3eli.pdf" -e robots=off;
I don't know why it's not running every minute once the terminal tells me that he's installing the new crontab.
Can somebody help me please?
Solution:
Thank you all for your help, the syntax as mcalex said should be
* */1 * * * path/to/script
if you want it to be executed every hour.
The cron job was working normally.However my mistake was simply writing permissions, in fact while executing the wget command, it's supposed to write the pdf file in the current workind directory which is a system directory in case of the cron tab. so i solved my problem simply by navigating to the Desktop directory before executing the wget command like so:
cd /Users/apple/Desktop/wget
and then do whatever i want to do.
PS: i should include the full path of the wget command too.
Thank you all for you help again:)
When you put 1 in the first column, it will run on the first minute (of every hour). In order to get it to run in every minute of every hour, you need to set the minute column as */1
So your line should read:
*/1 * * * * /Users/apple/Desktop/wget/down.sh
supporting links:
job every minute: https://bbs.archlinux.org/viewtopic.php?id=59180
job every 5 minutes: http://www.thegeekstuff.com/2011/07/cron-every-5-minutes/
1 * * * * /Users/apple/Destop/wget/down.sh
From this entry script will never run on every minute because it will run on first minute of every hour.
Make this change to your crontab file to run this script every min.
"* * * * * /Users/apple/Destop/wget/down.sh"
Do you have a typo? It looks like you might have mis-typed Desktop?
Another thing to do is to redirect the output of running the script to a file so you can see what's going on like this:
1 * * * * /Users/apple/Destop/wget/down.sh >> /tmp/cron.out
and then check out the file to see what's going on.
Did cron send you some email detailing what went wrong?
Does the script under that path exist?
Note that cron uses /bin/sh to execute commands.
Did you set a proper PATH in your script? wget may not be in the default PATH or there may be no PATH at all. Try using /path/to/wget in the script.
Note that downloading the same PDF file once a minute is probably a silly idea, though...
If your cronjob is writing things to disk then be careful that system preference "Put hard disk to sleep when possible" is unchecked.
This was preventing my cronjob backup tasks to execute.