LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 04-10-2014, 01:06 PM   #1
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-30
Posts: 5,290

Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916
cron every 45 minutes


hi, we had a script that was triggered to run every hour. now they want it to run every 45 minutes...

is there a sane way to automate this in cron or do i need to bash it out ?
 
Old 04-10-2014, 01:44 PM   #2
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ schneidz

You can use crontab -e to edit the crontab and put entry for that script in that as follows:

45 * * * * <full path to the script/script_name>

However, I am quite curious to know how they have configured it before to run every hour?

Last edited by T3RM1NVT0R; 04-10-2014 at 01:45 PM.
 
Old 04-10-2014, 01:56 PM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-30
Posts: 5,290

Original Poster
Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916
something like this is how it would be setup to run every hour
Code:
0 * * * * /path/to/script.ksh
i am wondering how to transform this into every :45 minutes ?

your example is to run it every hour (45 minutes past each hour).
what i am trying to accomplish is it running on a schedule like:
00:00
00:45
01:30
02:15
03:00
03:45
...

is this cron-able ?

Last edited by schneidz; 04-10-2014 at 02:00 PM.
 
Old 04-10-2014, 01:59 PM   #4
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ Reply

Quote:
# Example of job definition:$
# .---------------- minute (0 - 59)$
# | .------------- hour (0 - 23)$
# | | .---------- day of month (1 - 31)$
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...$
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat$
# | | | | |$
# * * * * * user-name command to be executed$
By default the first column is for minutes and the second one is for hour so I am assuming they have got something like below

Quote:
* 1 * * * <full path to script/script name>
Edited: Instead of 1 I have earlier put 0. This is what I think they have configured before.

Last edited by T3RM1NVT0R; 04-10-2014 at 02:04 PM.
 
Old 04-10-2014, 02:00 PM   #5
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 7
Posts: 3,528

Rep: Reputation: 974Reputation: 974Reputation: 974Reputation: 974Reputation: 974Reputation: 974Reputation: 974Reputation: 974
Run every 15 minutes and use a flag file for the time that it last ran:

Code:
0,15,30,45 * * * * find /path/flag -mmin +44 -exec touch /path/flag \; -exec /path/to/script \;

Last edited by smallpond; 04-10-2014 at 02:06 PM.
 
2 members found this post helpful.
Old 04-10-2014, 02:03 PM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-30
Posts: 5,290

Original Poster
Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916
Quote:
Originally Posted by T3RM1NVT0R View Post
By default the first column is for minutes and the second one is for hour so I am assuming they have got something like below
no, i think that would run every minute between midnite a 01:00 am.
 
Old 04-10-2014, 02:20 PM   #7
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Quote:
*/45 * * * * /path/to/script.ksh
should do.
 
1 members found this post helpful.
Old 04-10-2014, 02:21 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,191

Rep: Reputation: 3952Reputation: 3952Reputation: 3952Reputation: 3952Reputation: 3952Reputation: 3952Reputation: 3952Reputation: 3952Reputation: 3952Reputation: 3952Reputation: 3952
I'm not sure about sane but something this: Be sure to check my numbers.
30 1-23/3
15 2-22/3
00,45 00-22/3


I also found this but have not checked the math.
Code:
#!/bin/sh

# Minute Cron
# Usage: cron-min start
# Copyright 2014 by Marc Perkel
# docs at http://wiki.junkemailfilter.com/index.php/How_to_run_a_Linux_script_every_few_seconds_under_cron"
# Free to use with attribution

# Run this script under Cron once a minute

basedir=/etc/cron-min

if [ $# -gt 0 ]
then
   echo
   echo "cron-min by Marc Perkel"
   echo
   echo "This program is used to run all programs in a directory in parallel every X minutes."
   echo
   echo "Usage: cron-min"
   echo
   echo "The scheduling is done by creating directories with the number of minutes as part of the"
   echo "directory name. The minutes do not have to evenly divide into 60 or be less than 60."
   echo
   echo "Examples:"
   echo "  /etc/cron-min/1      # Executes everything in that directory every 1  minute"
   echo "  /etc/cron-min/5      # Executes everything in that directory every 5  minutes"
   echo "  /etc/cron-min/13     # Executes everything in that directory every 13 minutes"
   echo "  /etc/cron-min/75     # Executes everything in that directory every 75 minutes"
   echo
   exit
fi

for dir in $basedir/* ; do
   minutes=${dir##*/}
   if [ $(( ($(date +%s) / 60) % $minutes )) -eq 0 ]
   then
      for program in $basedir/$minutes/* ; do
     if [ -x $program ]
     then
        $program &> /dev/null &
     fi
      done
   fi
done

Last edited by michaelk; 04-10-2014 at 02:22 PM.
 
1 members found this post helpful.
Old 04-10-2014, 03:10 PM   #9
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-30
Posts: 5,290

Original Poster
Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916
this is what i ended up doing:
Code:
#!/bin/bash

sleep_timer=2700

while [ `date +%H` -ne 8 ]
do
 stuff
 sleep $sleep_timer
done
should stop on 8am tomorrow morning.
 
Old 04-24-2014, 12:23 PM   #10
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
See also http://www.dataphyx.com/cronsandbox/cronsandboxgui.php

Last edited by Habitual; 04-24-2014 at 12:24 PM.
 
Old 04-28-2014, 09:29 PM   #11
wstewart90
Member
 
Registered: May 2013
Distribution: Arch Linux
Posts: 86

Rep: Reputation: Disabled
Quote:
Originally Posted by T3RM1NVT0R View Post
should do.
This was your answer right here.

http://www.thegeekstuff.com/2011/07/...ery-5-minutes/
 
Old 04-29-2014, 07:25 AM   #12
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-30
Posts: 5,290

Original Poster
Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916
Quote:
Originally Posted by wstewart90 View Post
Quote:
[*/5 for every 5 minutes,] */10 for every 10 minutes, */15 for every 15 minutes, */30 for every 30 minutes, etc.
doesnt work for */45 since it is greater than half an hour.
 
Old 05-09-2014, 01:46 PM   #13
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by schneidz View Post
doesnt work for */45 since it is greater than half an hour.
as it has been said:
Code:
45 * * * * /path/to/script.sh
check it at http://www.dataphyx.com/cronsandbox/cronsandboxgui.php
 
Old 05-09-2014, 01:48 PM   #14
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-30
Posts: 5,290

Original Poster
Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916
^ isnt that for 45 minutes past each hour ? e.g.:
1:45
2:45
3:45
...
 
1 members found this post helpful.
Old 05-11-2014, 03:51 PM   #15
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by schneidz View Post
^ isnt that for 45 minutes past each hour ? e.g.:
1:45
2:45
3:45
...
darn, you are cron-rect.
 
  


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
Running a cron every 7 minutes but to cary over the 7 minute count to the next hour? ghurty Linux - Server 15 10-09-2013 06:45 PM
[SOLVED] Using Cron to make newusers every 10 minutes. Karas Linux - Newbie 18 11-21-2009 08:39 AM
find which program is calling cron every 10 minutes - using ubuntu intreoid getglenn Linux - Newbie 1 04-08-2009 03:53 AM
Cron every 5 minutes but not between midnight and 1 am xnomad Linux - Server 5 10-11-2007 12:17 PM
howto run a script from cron every 5 minutes except 11pm-8am ? cccc Programming 2 03-20-2005 03:52 AM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 10:19 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
Open Source Consulting | Domain Registration