Cron expression except between 8 am to 10 am - cron

I want to create a cron expression to allow except between 8 am to 10 am everyday.
* 0-8,10-23
is this right?

Yes, it's right.
Note it should have five fields (minute hour day-of-month month day-of-week) before the command line, or before the username and command line :
system-wide crontab:
* 0-8,10-23 * * * root command args
or user crontab:
* 0-8,10-23 * * * command args

Related

Offset cron job for only one instance? [duplicate]

Is it possible to have a cronjob run every 15 minutes (over every hour etc..) except for at 3AM?
I have another special cronjob I want to run at 3AM, but I don't want the other one to run at the same time...
With one cron line, no. With three, yes:
# Every 15 minutes except for 3:00-3:59
*/15 0-2,4-23 * * * thejob
# 3:15, 3:30, 3:45
15-45/15 3 * * * thejob
# 3:00 dead
0 3 * * * otherjob
I made my own solution, but I wanted to see what other people thought of!
I put this on the top of my desired script. I wanted it to not run at the half hour either so it doesn't do it on both.
On top of the script:
if [ $(date +%M) = 00 ] || [ $(date +%M) = 30 ]
then
exit
fi
The cron line:
*/15 * * * * ~/path/to/file
Hope anyone uses my solution too.
0,15,30,45 0,1,2,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 * * * your cron job

How can I email one of the cronjob lines to a different email address?

I have the MAILTO setting set in crontab to a certain email address, eg
a#ab.com
There are about 10 entries in the cron on different lines, running at different times and I want to add an 11th line but have it sent to a different email address.
How can I do this from within the crontab?
awk 'last ~ "<cert>" && $0 ~ "</cert>" {print FILENAME; nextfile} {last=$0}' *
I have tried using an output command but it is only outputting to a file.
Just add a different MAILTO line preceeding your 11th line - that setting will remain in effect for all subsequent cron lines:
MAILTO='a#ab.com'
* * * * * /cmd1
# other crontab jobs here, all emailing to 'a#ab.com'
* * * * * /cmd10
MAILTO='someone_else#ab.com'
# following crontab jobs emailing to 'someone_else#ab.com'
* * * * * /cmd11

Cronjob not running, attempting to echo string into file

My /etc/crontab looks like this:
* * * * * echo"Another 5 Minutes! " >> /tmp/5-minutes.txt
I figured this would append "Another 5 Minutes! " to /tmp/5-minutes.txt every minute. When I perform a 'less' command on the file, the changes are not there.
EDIT: If it helps, I have one other job in the crontab file, perhaps it's effecting the other job.
0 * * * * finger >> /tmp/hourly-finger.txt
* * * * * echo "Another 5 Minutes! " >> /tmp/5-minute.txt
Give a space after echo
echo "Another 5 Minutes! "
I figured it out. Because I'm editing the /etc/crontab directly I needed to specify a user for the crontab to run as. In my case I ran it as root so...
* * * * * root echo "Another 5 Minutes! : >> /tmp/5-minutes.txt

$ * * * * * echo "hi" => blado.kdb: command not found

I'm trying to set a cron job, namely echoing "hi" every minute.
When I do * * * * * echo "hi" I get blado.kdb: command not found. Any ideas how I could fix this?
Run crontab -e in your shell. This opens a text editor
Only then type * * * * * echo "hi". Save the file the text editor just opened for you
Your Cron task is now set
PS: echo "hi" will print "hi" in a void, if you want to see some results, set a task such as * * * * * touch /tmp/foo, and you'll see the modification date being updated every minute (ls -l /tmp/foo)

Crontab run every 15 minutes except at 3AM?

Is it possible to have a cronjob run every 15 minutes (over every hour etc..) except for at 3AM?
I have another special cronjob I want to run at 3AM, but I don't want the other one to run at the same time...
With one cron line, no. With three, yes:
# Every 15 minutes except for 3:00-3:59
*/15 0-2,4-23 * * * thejob
# 3:15, 3:30, 3:45
15-45/15 3 * * * thejob
# 3:00 dead
0 3 * * * otherjob
I made my own solution, but I wanted to see what other people thought of!
I put this on the top of my desired script. I wanted it to not run at the half hour either so it doesn't do it on both.
On top of the script:
if [ $(date +%M) = 00 ] || [ $(date +%M) = 30 ]
then
exit
fi
The cron line:
*/15 * * * * ~/path/to/file
Hope anyone uses my solution too.
0,15,30,45 0,1,2,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 * * * your cron job

Resources