LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-23-2009, 04:56 AM   #1
cooljai
Member
 
Registered: May 2007
Location: /dev/random
Distribution: CentOS, Fedora, RHEL, SuSE
Posts: 62

Rep: Reputation: 15
Question cron at every 51st minute


Hi,

I want to run a cronjob at every 51st minute (not every hour 51 minute).

for example, if first run is at 1:51, then second run should be at 2:42 (every 51st minute).

Is specifying */51 in minute field do the trick? or there's something else I need to consider?

Please suggest.
 
Old 02-23-2009, 05:05 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
No, that's not possible. Cron just periodically checks if any crontab entries match the current time. You'd need to write your own script to loop round or such like.
 
Old 02-23-2009, 05:34 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
As suggested by acid_kewpie you have to do this by the script itself. For example you can write instructions at the end of the script to update the crontab:
Code:
#!/bin/bash
<your code here>

# -----------------------------------------------------------
#  Update the crontab for the next job
# -----------------------------------------------------------
crontab < <(date -d "51 minutes" +"%M %H %d %m * $0")
Take in mind that the statement above overwrites the content of the crontab. If you have other entries in the actual crontab, they will be deleted. In this case you have to re-write them all from the script itself.
 
Old 02-23-2009, 05:58 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
if it's only there to run once, i'd have thought an "at" command would be nicer...?
 
Old 02-23-2009, 06:05 AM   #5
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044
I think the at command is suited better here.
Code:
#!/bin/bash
<your code here>

echo /path/to/your/script | at now+51 minutes
Doublecheck the syntax on at, else you will wait very long and see nothing happen.

jlinkels

=== Chris you were faster than I was!
 
Old 02-23-2009, 06:06 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
I agree. This would overcome the problem of overwriting the whole crontab, too.
 
Old 02-23-2009, 06:10 AM   #7
cooljai
Member
 
Registered: May 2007
Location: /dev/random
Distribution: CentOS, Fedora, RHEL, SuSE
Posts: 62

Original Poster
Rep: Reputation: 15
Thanks a lot!!

I'll have to take another look at requirement and make some more tweaks
 
Old 02-23-2009, 06:49 AM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
wrong thread. bum.

Last edited by acid_kewpie; 02-23-2009 at 06:52 AM.
 
  


Reply

Tags
cron


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
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
Cron - "incorrect minute" what's wrong? Vort3x Linux - Server 4 10-10-2007 04:55 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 01:57 AM
Can any one plz explain why/what for cron.d, cron.daily, cron.weekly etc are there. mavinashbabu Linux - Newbie 4 09-21-2006 01:50 PM
5 minute cron jobs for mrtg and gate_news shawn_t Linux - Software 3 12-22-2004 05:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:18 AM.

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