LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can I set Plesk Crontab to only run a job on Friday? (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-set-plesk-crontab-to-only-run-a-job-on-friday-721188/)

gogoskiracer 04-23-2009 11:16 AM

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?

MensaWater 04-23-2009 02:57 PM

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.

gogoskiracer 04-23-2009 04:07 PM

Quote:

Originally Posted by jlightner (Post 3518816)
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?

colucix 04-23-2009 04:45 PM

Just Fridays!

MensaWater 04-24-2009 01:57 PM

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.

gogoskiracer 04-26-2009 09:20 AM

Quote:

Originally Posted by jlightner (Post 3519841)
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?

colucix 04-27-2009 07:33 AM

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

michaelk 04-27-2009 01:44 PM

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

gogoskiracer 04-28-2009 09:49 AM

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!

gogoskiracer 05-15-2009 09:20 PM

Quote:

Originally Posted by gogoskiracer (Post 3523631)
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

colucix 05-16-2009 01:57 AM

Odd. I will try on my system. See you in two weeks... ;)


All times are GMT -5. The time now is 03:47 AM.