When does cronjob start running? - cron

I have this line for my cronjob
it's supposed to run every 2 hours
after running crontab -e
I saved this line
0 */2 * * * /Documents/scrapping/run.py
I was expecting the cronjob to start immediately after saving the file and then repeat every 2 hours
but when I saved the file- the script/cronjob wasnt running?
when is the cronjob being executed based on my script?

Related

Created cron job to run every 2 mint

I have configured cron job but it's not working.
I wanted to run the myfile.sh script for every 2 mint and below are my configuration in crontab.
# m h dom mon dow comman
2 * * * * /home/ubuntu/myfile.sh
myfile.sh is executable and contains below lines of code
#!/bin/bash
mysqldump -u[user] -p[password] --single-transaction --routines --triggers --all-databases > /home/ubuntu/backup_db10.sql
Is there anywhere we need to add configure anything?
You're running the script at two minutes past every hour. As in 1:02, 2:02 and so on.
You can change it to something like
*/2 * * * * /home/ubuntu/myfile.sh
to run it every two minutes.
A bit more info can be found here.

Cron.d file not running

I am new to Linux and have a problem that I have tried to look online and could not find a solution
I have 4 scripts that are running in cron.d 3 of them I set to run every minute and they are fine and logging into the output files but the last one should run at 1:00 am but it will not.
-rw-r--r-- 1 root root 390 Jul 29 14:03 Test
* * * * * root /usr/sa/dir1/dir2/script1.sh >> /usr/sa/dir1/logs/fileoutput 2>&1
* * * * * root /usr/sa/dir1/dir2/script2.sh >> /usr/sa/dir1/logs/fileoutput 2>&1
* * * * * root /usr/sa/dir1/dir2/script3.sh >> /usr/sa/dir1/logs/fileoutput 2>&1
0 1 * * * root /usr/sa/dir1/dir2/script4.sh >> /usr/sa/dir1/logs/fileoutput 2>&1
I checked the permission and all seems to be fine as the same script from cron.d file are running as I can see entries from cron that are executed in /var/log/messages and same from the log files.
Things I have tried till now and worked
IF I vim the file and change for the 4th script to run every minute it runs fine.
IF I vim the file and change for the 4th script to run during the day it runs.
IF I include the script under crontab of root user and it runs ok.
IF I run script form the command line it runs ok.
I can not figure out why viming the file in cron.d the script will be executed by cron.
Thank you in advance for the help
Things I have tried till now and worked
IF I vim the file and change for the 4th script to run every minute it runs fine.
IF I vim the file and change for the 4th script to run during the day it runs.
IF I include the script under crontab of root user and it runs ok.
IF I run script form the command line it runs ok.
I can not figure out why viming the file in cron.d the script will be executed by cron.
I don't see errors in /var/log/messages
Are you commiting this crontab by just editing the raw file or are you using crontab <my-new-crontab>? If you aren't then try the latter. :)
I end it up adding the scripts to the crontab of the user root and seems to be ok.

Why does this cron job run every minute?

I ran a cron job as ec2 user, in AWS server.
I set the cron command, like this
*/5 * * * * ec2-user bash ./dailyMailSend.sh
in crontab -e file.
It was set to run after every 5 minutes. But it runs every minute. Don't know why ?
For Amazon Linux use "0/5" instead of "*/5". This expression means every 5th minute from 0 through 59.
Next, do not specify relative paths in your crontab. Use only absolute paths.

Run immediately then every 4 hours in cron

How do you write a cron job which immediately run, then run on every hour divisible by 4? Say I started the script at 13:25, the job fires up right away, then the next run would be at 16:00, 20:00, 00:00 and so on.
For the first immediate run, just execute the command manually. Then set your cron up like this to have it execute continuously every 4th hour
0 */4 * * * yourCommand
This will run yourCommand every 4 hours (00:00, 04:00, 08:00......)

is it possible to create crontab that runs every 5 hours 30 minutes

I have to schedule execution of a .sh file for every 5 hours 30 minutes. is it possible to configure this way in linux crontab.
This should work. Also make sure your shell script should have valid permissions to exeucte.
30 */5 * * * sh yourscript

Resources