How can I set Plesk Crontab to only run a job on Friday?
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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?
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.
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?
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
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
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.
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:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.