LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 01-31-2014, 06:43 AM   #1
desiretolearn
LQ Newbie
 
Registered: Jan 2014
Posts: 25

Rep: Reputation: Disabled
crons


hi i want my crin job to run for every 20 minutes but it should run only 10 times

does this work. i am using bourne shel

then
Code:
20 **** /tmp/exmp.sh

Last edited by desiretolearn; 02-04-2014 at 05:03 AM.
 
Old 01-31-2014, 07:05 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,166

Rep: Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751
That won't work, you can't use that kind of logic within crontab.

You could do something like:

create a file runs.dat in the same folder as your script with echo 0 > runs.dat

Then in your script:

Code:
#!/bin/bash

let RUNS=($(cat runs.dat)+1)

echo ${RUNS} > runs.dat

if [ $RUNS -eq 10 ]; then
  chmod 644 $0
fi

#### REST OF SCRIPT HERE #####
This is a very dirty way of doing things, it basically says that after 10 runs of the script change the mode of the script to stop it being executable.
 
1 members found this post helpful.
Old 01-31-2014, 08:39 AM   #3
desiretolearn
LQ Newbie
 
Registered: Jan 2014
Posts: 25

Original Poster
Rep: Reputation: Disabled
oh thank you pal

Last edited by desiretolearn; 02-04-2014 at 05:03 AM.
 
Old 01-31-2014, 08:45 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,166

Rep: Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751
Quote:
Originally Posted by desiretolearn View Post
and in my cron now i can just give 20 **** /tmp/exmp.sh
this and execute is it??
That entry will cause your script to run once an hour at 20 minutes past the hour. To make it run every 20 minutes you can use

Code:
00,20,40 * * * * /tmp/exmp.sh
Some versions of Linux will also allow:
Code:
*/20 * * * * /tmp/exmp.sh
I'd suggest using the first version for now.

Try man 5 crontab for more information.

Last edited by TenTenths; 01-31-2014 at 08:47 AM.
 
1 members found this post helpful.
Old 02-04-2014, 01:35 AM   #5
desiretolearn
LQ Newbie
 
Registered: Jan 2014
Posts: 25

Original Poster
Rep: Reputation: Disabled
each time my cron is executing it is not updating the count in the file it keeps on executing
what might be the reason??? @tentenths
 
Old 02-05-2014, 03:47 AM   #6
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,166

Rep: Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751
Try changing the 2nd line of the script to:

Code:
let RUNS=($(cat /full/path/to/runs.dat)+1)
 
  


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
I am a user and I am not able to add/edit crons. unclesamcrazy Linux - Newbie 6 07-03-2013 01:25 AM
changed UID, now can't access crons BrianK Linux - General 4 05-23-2005 05:23 PM
Best Practice for Crons? Rotwang Linux - General 1 10-15-2004 05:23 PM
Mail - CRONs djoseph74 Linux - Software 1 09-02-2004 01:37 PM
crons robhargreaves Linux - General 2 01-27-2004 09:31 AM


All times are GMT -5. The time now is 02:56 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration