cron job for running a script based on db value - cron

I had a sctipt runthisapp.sh and I am having some dates in my db table holiday . My problem is every day it should check the db ,if the date is present in holiday table runthisapp.sh should run at 10'o clock
Else
It should run at 8'o clock.
I had tried but can't find the solution .Can you.help me.on this please

You can have two crontab entries, one at 8am, one at 10am, passing different options to your script, e.g. the former takes --holiday=0, and the latter --holiday=1, and your script should just return doing nothing if in the wrong "holidayness".

Related

The following code has been giving me the same output for a long time

I have been writing some code with PRAW. I want the following to give the top posts each day.But it has been returning the same ids even though new posts are submitted each day and different posts are at the top. What should I do?
import praw
reddit=praw.Reddit(client_id='id',
client_secret='secret',password='password',
user_agent='agent',username='username')
top_funny=subreddit.top(limit=1)
for submission in top_funny:
print(submission)
by default subreddit.top() returns the top of all time. You can change this by using the time_filter parameter and specify any of the following: hour, day, week, month, year, all.
ex:
subreddit.top("day", limit=1)
will return the top submission from today.
As LampToast said, you should use the time_filter.
Arguments for .top() are listed in the docs:
Parameters: time_filter – Can be one of: all, day, hour, month, week, year (default: all).
https://praw.readthedocs.io/en/latest/code_overview/models/multireddit.html#praw.models.Multireddit.top

Does AirFlow support custom calendar or Flexi calendar?

I have one requirement, in my application every month TWS job get trigger on different dates. For example, Monthly job in Jan will run on 10th and in Feb it will run on 15th and in march on 20th ....Is there any way to implement this in AirFlow ? Not sure if we can do this using Crons, since day(dd) is different in each month. Does AirFlow support custom calendar ?
Not sure if we can do this using Crons, since day(dd) is different in each month
One way to do that is to use BranchOperator that will call your Python function with the business logic:
dag = DAG(....) # trigger daily
def define_datetime(context):
# here your logic to find the route to follow, depending on the execution time
# you should find this date in context['execution_date']
return "execute" if date_is_expected() else "pass"
with dag:
branch = BranchPythonOperator(
...
)
pass = DummyOperator(task_id='pass',...)
execute = PythonOperator(task_id='execute'...) # or any operator that will execute the job
branch >> [pass, execute]

How can I to restrict the execution of an imacros script between some hours?

I have an imaros script that runs each 4 minutes (using auto clicker)... but I need to it doesn't run between 23:30 to 00:30... so I need to do something like:
If (date is <23:30 and date is > 00:30) then run!!
Is this possible?
many thanks!
This is possible with JavaScript. You can create current time in JS and compare it with time between the two times you named. It's a little complicated to make. Msg me on private messages and we can work things out.

Records get skipped Due to timeZone difference between Server and cllients in Nodejs Rethinkdb?

iam filtering some records from my Rethinkdb . the code works just fine when i use the following code . but it works with date only
(new Date(filter.fromdate+' 00:00 GMT+00:00'));
the line above works perfect even after the server is on different region. By using above . It wont skipp any records and time and date just works fine .
but when i use date with time it throws error of rangeError invalid time
I am saving date in rethink in the following format Mon Feb 20 2017 07:25:27 GMT+00:00
SomeHow i just need time with my date to work with the above mentioned code or may be other method can also be used .
Ok, so you need to check if filter.fromdate is with time:
If with time don't add your time and modify it with the proper method of Date , otherwise if is a date without time add your time. And remember you can use momentjs instead of Date to handle dates. Hope help you man.

Cron Jobs Linux row deletion

I'm running this script;
$query = "SELECT * FROM XXX WHERE email='$Email'";
if($count==1) // fails
if($count==0) // succeeds
If successful
mysql_query ("INSERT INTO XXX (email) values ('$Email'");
Then proceeds onto the next script.
So, it checks to see if you have already ran this script in the past on that account, if you have your email is stored then you can't run this script ever again on that same email.
However, after this script has been processed I want it to delete the row created for the email after 6 hours.
So that after 6 hours they may run the script again.. I've been enlightened that I need to use Cron jobs for this, But I'm not sure how.. Any help is highly appreciated!
Many regards, and thanks in advance.
0 0,6,12,18 * * * /path/to/mycommand
This means starting from hour 0, 6, 12, and 18 the cron job would run. That would be the cron needed to do what you want.
Depending on which linux version you are running you will need to see how to actually create the cron job.
I would think at now +6 hours is a better choice here.

Resources