LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-21-2012, 05:02 AM   #1
manju98458
LQ Newbie
 
Registered: Nov 2012
Posts: 20

Rep: Reputation: Disabled
Stoping the cron at particular time and date


Greeetings,

i am running monitoring script with the help of cron.

i need to stop the cron at friday some time for the backup

purpose . How to schedule in cron.
 
Old 11-21-2012, 05:10 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
well naturally a cron entry is trivial enough to write...

0 20 * * 5 /path/to/script

but what your script needs to do is something we can't comment on as you've not gone into it in any depth at all.
 
Old 11-21-2012, 05:22 AM   #3
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,452

Rep: Reputation: 85
I'm not understanding your question.

Stopping cron on friday will run a script...

How can cron run a script if cron is stopped?

Or you want to stop cron from running a monitor script while a backup is running on Fridays?

Then, tell cron not to run the script on Friday.

The syntax is ->

Quote:
* * * * * command to be executed
┬ ┬ ┬ ┬ ┬
│ │ │ │ │
│ │ │ │ │
│ │ │ │ └───── day of week (0 - 7) (0 or 7 are Sunday, or use names)
│ │ │ └────────── month (1 - 12)
│ │ └─────────────── day of month (1 - 31)
│ └──────────────────── hour (0 - 23)
└───────────────────────── min (0 - 59)
So to run a script every day except friday,

crontab -e

* * * * 1,2,3,4,6,7 /path/to/script

Notice I excluded 5 because the 5 represents Friday.

Last edited by fakie_flip; 11-21-2012 at 05:25 AM. Reason: corrected an error
 
1 members found this post helpful.
Old 11-21-2012, 05:26 AM   #4
manju98458
LQ Newbie
 
Registered: Nov 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
I have monitoring script which monitors the services with help of cron with regular interval of time. on Friday we have to take the backup of the servers by stopping the services. At the time we will get huge mail alert for the service down. So during the backup window the cron should be stopped and when the backup compeletes it should continue to monitor

Last edited by manju98458; 11-21-2012 at 05:32 AM.
 
Old 11-21-2012, 05:28 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
Update the script to check the time when it runs, or put in two cron entries, one for all day Saturday to Thursday, and one for 22, 23 hours on friday as required.
 
Old 11-21-2012, 05:59 AM   #6
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,452

Rep: Reputation: 85
Ok, so you can tell cron to run the monitor script each day except Friday like I said. Can you not?

If you really want to turn off cron completely.

Do as root:

at 11:55 AM Fri
> service crond stop
> EOT

Check the job with:

atq

You're backup finishes before 5pm, then as root:

at 5:00 PM Fri
> service crond start
> EOT

Unlike cron, "at" will not run commands on intervals, so these commands will only run one time on Friday, not each Friday after that.

But you can make cron run "at" on intervals. Then use "at -f file", so it doesn't require any user input.

Last edited by fakie_flip; 11-21-2012 at 06:07 AM. Reason: fixed cron to crond
 
Old 11-21-2012, 06:03 AM   #7
manju98458
LQ Newbie
 
Registered: Nov 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
No I dont want to stop the cron entire friday, I want to stop only few hours during the backup window also we have another crons are running in the same server if we completely stop the cron services. It will affect to the other monitoring

Last edited by manju98458; 11-21-2012 at 06:05 AM.
 
Old 11-21-2012, 06:08 AM   #8
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,452

Rep: Reputation: 85
Wait...

Last edited by fakie_flip; 11-21-2012 at 06:10 AM.
 
1 members found this post helpful.
Old 11-21-2012, 06:15 AM   #9
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
Quote:
Originally Posted by manju98458 View Post
No I dont want to stop the cron entire friday, I want to stop only few hours during the backup window also we have another crons are running in the same server if we completely stop the cron services. It will affect to the other monitoring
read my reply then
 
Old 11-21-2012, 06:17 AM   #10
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,452

Rep: Reputation: 85
crontab -e

* 10 * * 5 kill $(pidof script)
* 14 * * 4 /path/to/script

This will stop the script at 10:00 AM on Friday. Then it will start the script at 2:00 PM Friday

During 10am to 2pm, backup starts and finishes. Adjust the times.

Last edited by fakie_flip; 11-21-2012 at 06:19 AM.
 
Old 11-21-2012, 06:40 AM   #11
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
well is this script running constantly via cron, or monitoring once per cron invocation? It's presumably a pretty popor solution if it's persisting for a long period of time from a single cron job.
 
Old 11-21-2012, 06:47 AM   #12
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,452

Rep: Reputation: 85
Sounds like it's running constantly since he needs to stop it for a few hours, and it's not stopping on it's own.
 
Old 11-21-2012, 06:49 AM   #13
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
I'd read that that means "the checks need to not be done for a period of time", regardless of how the checks are actaully being executed each time.
 
Old 11-21-2012, 07:09 AM   #14
manju98458
LQ Newbie
 
Registered: Nov 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
Cron is running every 17 minutes, PID I have checked under /var/run/cron.id
 
Old 11-21-2012, 07:11 AM   #15
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
17?? how on earth do you run cron every 17 minutes? Do you mean on the 17th minute of each hour?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how do i log the start/completion (time&date) of my cron job script? davide123 Linux - Newbie 3 01-11-2010 07:25 PM
Cron Jobs with time not just date! gelni Linux - Newbie 10 12-01-2008 12:58 PM
how to convert windows date and time to unix date and time jitupatil_2007 General 8 03-31-2008 06:58 AM
Start Date + Time Duration = End Date/Time calculator? ToBe Linux - General 3 09-26-2005 11:17 AM


All times are GMT -5. The time now is 06:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration