CRONTAB changing in script - linux

my task is to make a script which does server snapshots once a day for 7 days, then
once for a week for 3 weeks moving to once for a month for 12 months. And the question is how can I change
frequency of doing snapshots in CRONTAB without changing CRONTAB manually after 7 days then 1 month etc.

I'm afraid that this is three separate entries in the cron table, including start and end time/date. Coding this as a continuing time check from the start date is simply overkill, unless you have some need to restart this sequence every 3-12 months.

Related

Run crontab very 14th working day of month at 10h [duplicate]

This question already has answers here:
Cron job every three days
(12 answers)
Closed last month.
please i want to create crontab that should runs evry 14th working day at 10am.
Im tried this row but still not giving what i want.
0 10 14 * 1-5
Thank you in advance
This will make it run on the 14th of the month (if that day falls between monday and friday)
0 10 */14 * 1-5
If you want it to run every 14 working days, you might want the cron job to call a script. Tell cron to run every day at 10. The script can then keep track of last time it ran, compare it and run if it's been 14 days and if today is a weekday.

cronjob executed on wrong day

I want a script to be executed each first Saturday of a quarter.
Therefore I have set a crontab line up with the following
24 9 1-7 1,4,7,10 6 /absolute/path/to/script
This script was now executed yesterday, at 9:24 (ok),on Saturay (ok), but on October(ok) 16th(NOK).
Any hints what I missed or misunderstood?
Thanks a lot.
The script runs every day the first 7 days and every Saturday of the specified months.
The reason is well explained in this crontab guru page (and crontab(5)'s man page). The relevant piece is:
Note: The day of a command's execution can be specified in the following two fields --- 'day of month', and 'day of week'. If both fields are restricted (i.e., do not contain the "*" character), the command will be run when either field matches the current time. For example,
"30 4 1,15 * 5" would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday.
You can check that this is indeed what happens by checking the description and when your script will be run next ("next at") here.
The way to achieve what you want, i.e., run the script on the first Saturday, is described in other questions/answers. See, for instance, Run a cron job on the first Monday of every month? or How to schedule to run first Sunday of every month. In short, replace 6 with * and combine your command with a call to date.

direct admin, run cron only in week-days

I want to set up cronjob in the Direct Admin panel only while week-days without Sundays and Saturdays. additionally I need run this 3 time a day no certain hours. Can I do that with 1 command?
Sure. To take care of running things only on weekdays, enter a range in the Day of Week field. 0=Sunday, so you want "1-5" in that field. To run a command multiple times, you would use commas to separate the hours you want it to run. For example, to run at 0100, 0900, and 1700, enter "1,9,17" in the Hour field and "0" in the minute field.

Run cron job every 2 days on specified hour

How can I run a cronjob for every 2 days on a specified hour like 4:10 AM?
Is the following expression right?
10 04 * * */2 MY-COMMAND
No, you are running on days of the week which are evenly divisible by two. So you are running it on Sun, Tue, Thu, Sat; Sun, Tue, ... (This field is zero-based.)
If you move the */2 to the month field instead (fourth field), you get the same problem with uneven periodicity in months with an uneven number of days, but the aberrant days will happen only seven times a year (eight in leap years) instead of every week.
If you absolutely require the job to run every other day, you need some kind of external logic. Maybe make the script check a run file, and abort if it's less than 25 hours old (or maybe 26 if you change the system time for daylight saving time) and otherwise proceed and update the time stamp of the run file.
If you look at the job execution days you can find that it also depends on the month that you are using (ex) if you are trying to execute every 5 day then the job will be start and it will try to split the month in equal halfs (which is not) and thus it wont work as expected seeClick Here to check so it becomes mandatory to use the withIntervalInHours(intervalInHours) to get our case working

run cron job on end of every month

I need to run a script at 2 pm on the end of every month. The reason i set 2 pm is i've a timezone of asia/calcutta and it differs 10 hrs and 30 min. from the server time.
I've set date_default_timezone_set('Asia/Calcutta') in my script, so for the current settings i can trigger 1st day of every month as per my timezone.
But the issue is, i'm using webmin and there is no settings to run end of every month and only date from 1 - 31 listed. Here i attached the screenshot.
How can i run the script on end of the every month at 2pm?
Any help greatly appreciated, Thanks!.
The simple way, but ugly
is set to run on every 28,29,30,31 days. Each time when script is launched compare current day with max days in current month using bash/oerl script
Have it run every day starting the 28th of every month through the first of the next month. In the script, check if tomorrow is the first day of a month. If so, run, else die.

Resources