Jump to content

Welcome to Rune Tips, the first ever RuneScape help site. We aim to offer skill guides, quest guides, maps, calculators, informative databases, tips, and much more to help you get the most from the Massive Online Adventure Game, RuneScape, by Jagex Ltd © 2009.

Report Ad

Welcome to Forum.Tip.It
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. If you already have an account, login here - otherwise create an account for free today!
Photo

Cron jobs


  • Please log in to reply
15 replies to this topic

#1
Mercifull
[ Display Name History ]

Mercifull

    Post Junkie

  • Members
  • 16,130 posts
  • Gender:Male
  • Location:In a house where everything is coated in cat fur
  • Joined:18 June 2004
  • RuneScape Status:P2P
  • RSN:Mercifull
  • Clan:Tip.It
Quick question...

How do I make a cron job to repeat every 4 weeks as opposed to the same day each week/month.

Thanks.

Posted Image
Mercifull <3 Suzi

"We don't want players to be able to buy their way to success in RuneScape. If we let players start doing this, it devalues RuneScape for others. We feel your status in real-life shouldn't affect your ability to be successful in RuneScape" Jagex 01/04/01 - 02/03/12

#2
Hedgehog
[ Display Name History ]

Hedgehog

    ???

  • Monster Hunting Team Leader
  • 7,789 posts
  • Gender:Not Telling
  • Joined:18 November 2006
  • RuneScape Status:Retired
Run it every day
Increment it each time it runs
When it reaches 28, run what you need to run
Reset it

#3
Mercifull
[ Display Name History ]

Mercifull

    Post Junkie

  • Members
  • 16,130 posts
  • Gender:Male
  • Location:In a house where everything is coated in cat fur
  • Joined:18 June 2004
  • RuneScape Status:P2P
  • RSN:Mercifull
  • Clan:Tip.It
I'm using DirectAdmin to maintain my crons (see screenshot below)

At the moment I have to change those dates in the cron manually. I'm not so fussed by the filename as I can happily live with yymmdd-showname-showname.mp3 as it'll be edited before the next time it airs anyway.

How would I set that to increment and activate on the 28th run?

Posted Image

Posted Image
Mercifull <3 Suzi

"We don't want players to be able to buy their way to success in RuneScape. If we let players start doing this, it devalues RuneScape for others. We feel your status in real-life shouldn't affect your ability to be successful in RuneScape" Jagex 01/04/01 - 02/03/12

#4
Hedgehog
[ Display Name History ]

Hedgehog

    ???

  • Monster Hunting Team Leader
  • 7,789 posts
  • Gender:Not Telling
  • Joined:18 November 2006
  • RuneScape Status:Retired
Have it run one day per week on the day you want it to run.
The first part of the code should look like this:


$date = json_decode(file_get_contents("weekcount.json"),true);
if($date['count'] < 4){
$date['count']++;
file_put_contents("weekcount.json", json_encode($date['count']));
}
if($date['count'] == 4){
$date['count'] = 0;
file_put_contents("weekcount.json", json_encode($date['count']));
...
}
}


Not sure if that will compile, I just did it from memory. Basically, keep the # of weeks in a file and read it and update it as necessary.

#5
MageUK
[ Display Name History ]

MageUK

    Behind You

  • Administrators
  • 2,371 posts
  • Gender:Male
  • Location:#runescape
  • Joined:21 May 2006
  • RuneScape Status:Retired
  • RSN:Pure_MageUK
Well I was replying to this topic before everything died, so here goes.

You can kind of do this with raw cron jobs but you also kind of can't.

Cron jobs can run every 28 days, but they always have to have a base point to start with relative to the current month (in terms of days).

So, for example, a cron job set to run at:
* * 1/28 * *

It will run every 28 days, relative to the first day of the month. So it will run on the 1st and 29th of each month, which isn't quite what you want. Unfortunately you just can't do this, so you would need an addition to your script to do it for you.


#6
Mercifull
[ Display Name History ]

Mercifull

    Post Junkie

  • Members
  • 16,130 posts
  • Gender:Male
  • Location:In a house where everything is coated in cat fur
  • Joined:18 June 2004
  • RuneScape Status:P2P
  • RSN:Mercifull
  • Clan:Tip.It
Bugger. I was worried that would be the case. I've got about 80 crons set up to record live airings of radio shows at specific times and save them to a folder on the webserver. However as we have 4 weekly schedule it means every few weeks I need to make sure I reset the dates on the crons again for the next live show. This works but occasionally I forget and then I need to snag the recording from one of the two backup locations which requires physical access to the studio. I'd rather do this maintenance remotely from my home.

I was hoping it was possible to just set them up once and then repeat every 28 days.

Posted Image
Mercifull <3 Suzi

"We don't want players to be able to buy their way to success in RuneScape. If we let players start doing this, it devalues RuneScape for others. We feel your status in real-life shouldn't affect your ability to be successful in RuneScape" Jagex 01/04/01 - 02/03/12

#7
obfuscator
[ Display Name History ]

obfuscator

    Tanned Caveman

  • Members
  • 20,231 posts
  • Gender:Not Telling
  • Joined:6 March 2008
  • RuneScape Status:Retired
How about another cron job to reset the dates on the crons? :P

polvCwJ.gif
"It's not a rest for me, it's a rest for the weights." - Dom Mazzetti


#8
Mercifull
[ Display Name History ]

Mercifull

    Post Junkie

  • Members
  • 16,130 posts
  • Gender:Male
  • Location:In a house where everything is coated in cat fur
  • Joined:18 June 2004
  • RuneScape Status:P2P
  • RSN:Mercifull
  • Clan:Tip.It

How about another cron job to reset the dates on the crons? :P

Is that possible? Sounds a bit obvious but it could work?

Posted Image
Mercifull <3 Suzi

"We don't want players to be able to buy their way to success in RuneScape. If we let players start doing this, it devalues RuneScape for others. We feel your status in real-life shouldn't affect your ability to be successful in RuneScape" Jagex 01/04/01 - 02/03/12

#9
Markup
[ Display Name History ]

Markup

    Scorpion Pit

  • Members
  • 639 posts
  • Gender:Not Telling
  • Joined:9 April 2006
  • RuneScape Status:None
Could you explain the reason for needing to repeat/reset every 4 weeks?

Edit: I have read the whole thread, I don't understand why this solution is required if fixed date live shows are say every friday night.

#10
MPM
[ Display Name History ]

MPM

    Retired Crew Leader

  • Members
  • 2,847 posts
  • Gender:Not Telling
  • Joined:23 May 2004
  • RuneScape Status:Retired
  • RSN:MPM
Hey Merc, here is a simpler way to do it than what has been offered so far. It's in bash, because your cronjobs were all .sh, but it should be simple to adjust to whatever language you want.



#!/bin/bash

START=`date --date="2012-12-21" +"%G%V"` #get the year and week number of the starting date. This will be in the format "201251"
TODAY=`date +"%G%V"` #get the year and week number of the current date in the same format.
let "DIFF=($TODAY-$START)%4" #Subtract the two. This leaves the number of weeks between the two dates. Then, get mod4 of it.

if [[ $DIFF == 0 ]] ; then #If the mod4 ==0, then it is a multiple of 4 weeks after the start date.
echo "Fourth Week"
#Do stuff here.,like call the script that will do the work
fi

A leap year might screw this up, but I'm not certain. I do know that this is accurate up until May of 2015.

Make sure to set the cron job up to run on the correct day of the week and this will work for you.

00 17 * * 5 <script>
Will run it every Friday at 5:00pm. If it happens to be the fourth week after your start date, it will run the script you tell it to.

~M


#11
obfuscator
[ Display Name History ]

obfuscator

    Tanned Caveman

  • Members
  • 20,231 posts
  • Gender:Not Telling
  • Joined:6 March 2008
  • RuneScape Status:Retired


How about another cron job to reset the dates on the crons? :P

Is that possible? Sounds a bit obvious but it could work?


I was just making a bad joke :P

polvCwJ.gif
"It's not a rest for me, it's a rest for the weights." - Dom Mazzetti


#12
Mercifull
[ Display Name History ]

Mercifull

    Post Junkie

  • Members
  • 16,130 posts
  • Gender:Male
  • Location:In a house where everything is coated in cat fur
  • Joined:18 June 2004
  • RuneScape Status:P2P
  • RSN:Mercifull
  • Clan:Tip.It

Could you explain the reason for needing to repeat/reset every 4 weeks?

Edit: I have read the whole thread, I don't understand why this solution is required if fixed date live shows are say every friday night.


Let me explain a little more. We are a community radio station where everyone is a volunteer. Our schedule is quite complex.

There are two live shows every Wednesday (easy to make a cron) however there are also some shows on wednesday which are only on every 2 weeks or even once a month. Saturday and Sundays have live shows but those shows are only on once every 4 weeks. There is also a monday show every 4 weeks too. One off random specials during the week aren't an issue as they are not regular.

We run a 4 weekly schedule (http://frome.fm/wp-c...-v18-Sheet1.pdf) the ones with red backgrounds are live shows.

You can see my frustration :(

Misplacedme: I'll look into that later as I need to pop out now. :)

Posted Image
Mercifull <3 Suzi

"We don't want players to be able to buy their way to success in RuneScape. If we let players start doing this, it devalues RuneScape for others. We feel your status in real-life shouldn't affect your ability to be successful in RuneScape" Jagex 01/04/01 - 02/03/12

#13
Markup
[ Display Name History ]

Markup

    Scorpion Pit

  • Members
  • 639 posts
  • Gender:Not Telling
  • Joined:9 April 2006
  • RuneScape Status:None
Perhaps,

test.cron
* * * * * /home/test/scripts/fortcronjob.sh 10 2 >> /home/test/scripts/fortcronjob.log 2>&1 && date >> /home/test/scripts/test.cron.log 2>&1

Posted Image

fortcronjob.sh
dir_data="/home/test/.fortcronjob/"
if [ $# != 2 ]
then
echo "Usage: unique_id week_modulus"
exit 1
fi
instance_id=$1
instance_mod=$2
counter=0
exit_value=1
file_data="$dir_data$1"
if [ ! -e "$file_data" ]
then
echo "id:$instance_id - no data, starting from 0"
else
source "$file_data"
fi
counter=$(( $counter % $instance_mod ))
if [ $counter == 0 ]
then
echo "id:$instance_id - true"
exit_value=0
else
echo "id:$instance_id - t-$(( $instance_mod - $counter ))"
fi
counter=$(( $counter + 1 ))
echo "counter=$counter" > "$file_data"
exit $exit_value

mkdir ~/.fortcronjob/
edit fortcronjob.sh to refer to ~/.fortcronjob/ as an absolute path( non relative )
chmod fortcronjob.sh (I think it just needs +x for others)
Give each cronjob task a seperate id and required modulus value
Make sure you leave in the stdout/stderr redirection for the fortcronjob.sh script otherwise it'll spam your mail
* * * * * /home/test/scripts/fortcronjob.sh ID MODULUS >> /home/test/scripts/fortcronjob.log 2>&1 && COMMAND HERE

brb dinner

Edit:

I used a number for ID, but it can be any valid file name.

You'll need to implement each counter on the week it should start, else you'll need to go around editing the counter files.

Every 4weeks Monday = MODULUS 4, with the counter @ 0 on that week.
Every 2weeks Wednesday = MODULUS 2, with the counter @ 0 on one of the weeks.

#14
Mercifull
[ Display Name History ]

Mercifull

    Post Junkie

  • Members
  • 16,130 posts
  • Gender:Male
  • Location:In a house where everything is coated in cat fur
  • Joined:18 June 2004
  • RuneScape Status:P2P
  • RSN:Mercifull
  • Clan:Tip.It
Wouldn't that require me to make a script for each individual show though? At the moment it's the same basic script that just runs as different times naming the file.

Posted Image
Mercifull <3 Suzi

"We don't want players to be able to buy their way to success in RuneScape. If we let players start doing this, it devalues RuneScape for others. We feel your status in real-life shouldn't affect your ability to be successful in RuneScape" Jagex 01/04/01 - 02/03/12

#15
Markup
[ Display Name History ]

Markup

    Scorpion Pit

  • Members
  • 639 posts
  • Gender:Not Telling
  • Joined:9 April 2006
  • RuneScape Status:None

Wouldn't that require me to make a script for each individual show though? At the moment it's the same basic script that just runs as different times naming the file.


Same script for each show, different arguments for each cronjob.

We're using the && operator (command?) to process 2 commands.
script1.sh && script2.sh
If script1.sh exits with success, then it'll process script2.sh. If script1.sh exits with an error, then script2.sh will not be processed.

* * * * * /home/test/scripts/fortcronjob.sh ID MODULUS >> /home/test/scripts/fortcronjob.log 2>&1 && COMMAND HERE

Your current cron command replaces COMMAND HERE at the ende

Maybe:

Monday @ 8pm, every 4 weeks from the first monday you implement the counter.

0 20 * * MON * /home/test/scripts/fortcronjob.sh "soulshow_monday_every_4_weeks" 4 >> /home/test/scripts/fortcronjob.log 2>&1 && /home/test/lagain.sh "Ivor's Show" soulshow "ivor_soulshow.mp3" 70


#16
Mercifull
[ Display Name History ]

Mercifull

    Post Junkie

  • Members
  • 16,130 posts
  • Gender:Male
  • Location:In a house where everything is coated in cat fur
  • Joined:18 June 2004
  • RuneScape Status:P2P
  • RSN:Mercifull
  • Clan:Tip.It
Thanks. Sadly I'm off to Italy for a little while but I'll run some tests on my return. I might need to set it up to record a replay (to avoid messing up a regular recording) for 4 weeks and see what happens :)

Posted Image
Mercifull <3 Suzi

"We don't want players to be able to buy their way to success in RuneScape. If we let players start doing this, it devalues RuneScape for others. We feel your status in real-life shouldn't affect your ability to be successful in RuneScape" Jagex 01/04/01 - 02/03/12




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users