LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 04-23-2009, 11:16 AM   #1
gogoskiracer
LQ Newbie
 
Registered: Jan 2009
Posts: 13

Rep: Reputation: 0
How can I set Plesk Crontab to only run a job on Friday?


Plesk seems to require every field to be filled. This makes sense in most cases, but I'm trying to have a job run only on every Friday night. How can I do this if the "Day of the Month" field can't be blank? If I enter a value for this field, for example "1", then won't the job run every Friday AND on the 1st of every month?
 
Old 04-23-2009, 02:57 PM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,003
Blog Entries: 5

Rep: Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782
Not sure what Plesk is but are you saying it doesn't allow asterisk in that field like most other crontab implementations?

Try typing "man 5 crontab" if this is a Linux variant.
 
Old 04-23-2009, 04:07 PM   #3
gogoskiracer
LQ Newbie
 
Registered: Jan 2009
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jlightner View Post
Not sure what Plesk is but are you saying it doesn't allow asterisk in that field like most other crontab implementations?

Try typing "man 5 crontab" if this is a Linux variant.
Plesk is the control panel software running on our Linux server.

I can put an asterisk in the box, but that will mean every day of the month, won't it? If I do "Day of the Month: *" and "Day of the Week: Friday", will the cron job run every day of the month or just Fridays?
 
Old 04-23-2009, 04:45 PM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,498

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
Just Fridays!
 
Old 04-24-2009, 01:57 PM   #5
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,003
Blog Entries: 5

Rep: Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782
Just Fridays when you have specified day of the week.

I understand the confusion though. If you had actual entries other than * in both fields it would run on both specifications.
By putting the * though you're not telling WHEN to run - you're telling it it is ALLOWED it to run on every day so it then looks to the rest of the specification to determine when to run.
 
Old 04-26-2009, 09:20 AM   #6
gogoskiracer
LQ Newbie
 
Registered: Jan 2009
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jlightner View Post
Just Fridays when you have specified day of the week.

I understand the confusion though. If you had actual entries other than * in both fields it would run on both specifications.
By putting the * though you're not telling WHEN to run - you're telling it it is ALLOWED it to run on every day so it then looks to the rest of the specification to determine when to run.
Ok, that's really helpful. Thanks. That actually brings up another question then. If I want to do it every other Friday, how would I do that? Would it be Day of the Week: Friday/2? OR Day of Month: */2, Day of the Week: Friday? Or is it not possible?
 
Old 04-27-2009, 07:33 AM   #7
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,498

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
I think it is not possible. You can run every Friday and put a condition inside the script itself. For example check if the day of the month is in the first week or in the third week of the current month (you skip the second and the forth Friday). However it happens that a month has 5 Friday, so the problem is to run your script every 14 days, not only the first and third Friday of the month. In this case it would be better to create an empty file every time you execute the script and check if the current date is 14 days after the modification date of that file. You can also create a file containing the date in its name. For example:
Code:
#!/bin/bash
#
# check if exist a file whose name is "14 days before today":
#
if [ -f $HOME/.$(date -d "14 days ago" +%Y%m%d) ]
then
  #
  # your commands here (the content of the whole script)
  #

  #
  # remove the old file
  #
  rm $HOME/.$(date -d "14 days ago" +%Y%m%d)

  #
  # create the new one
  #
  touch $HOME/.$(date +%Y%m%d)
fi
this will create and check an hidden file in your home directory whose name has format .yyyymmdd
 
Old 04-27-2009, 01:44 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 11,891

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
There is no simple crontab setting that will that do what you want.
Has not been tested but it is supposed to check for even/odd weeks (0-53). So when %ON_WK=0 it is an even week.
Setup crontab to run every Friday.

#!/bin/sh

WK=`date +%W`
ON_WK=`expr $WK % 2`

if [ $ON_WK = 0 ]; then
do something constructive here.
fi
 
Old 04-28-2009, 09:49 AM   #9
gogoskiracer
LQ Newbie
 
Registered: Jan 2009
Posts: 13

Original Poster
Rep: Reputation: 0
Thanks for your help! That's a good suggestion colucix to use the code to determine if it should run on a given week. michaelk, I like the idea of seeing if the week of the year is even or odd.

Plesk seems to have accepted day of the month: */2, day of the week: Friday and hasn't been running every other day. It's yet to be seen if it will run on every other Friday, but it's looking promising.

I'll post what I find out. If it doesn't work, I'll have to add the code to the script that you guys are suggesting.

Thanks again!
 
Old 05-15-2009, 09:20 PM   #10
gogoskiracer
LQ Newbie
 
Registered: Jan 2009
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by gogoskiracer View Post
Plesk seems to have accepted day of the month: */2, day of the week: Friday and hasn't been running every other day. It's yet to be seen if it will run on every other Friday, but it's looking promising.

I'll post what I find out. If it doesn't work, I'll have to add the code to the script that you guys are suggesting.
So, against all bets, it seems that it actually can be as simple as I had hoped. Plesk has run the cron every other Friday!

For others out there with the same question, here's the way to do it:

Day of the Month: */2
Day of the Week: Friday
 
Old 05-16-2009, 01:57 AM   #11
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,498

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
Odd. I will try on my system. See you in two weeks...
 
  


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
the crontab job is not run ust Linux - Software 1 03-24-2008 07:03 PM
Run crontab job problem ust Linux - Software 4 07-30-2007 01:24 AM
Cron Job to run on 2nd and 4th Friday of each month rust8y Linux - General 1 06-25-2007 09:07 PM
Run crontab job sunhui Linux - Software 2 05-16-2007 08:35 PM
Cron job to run every monday wednesday and friday...? init Linux - General 4 07-29-2004 11:24 AM


All times are GMT -5. The time now is 12:47 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration