How to run a shell script once a day?

2024/7/5 12:15:48

I am trying to run this particular shell script only one time, daily. Here's my code for runLucene.py:

#!/usr/bin/env pythonimport os
from extras.download_datos_desambiguar import news_Lucenex=datetime.today()
y=x.replace(day=x.day, hour=09, minute=00, second=0, microsecond=0)
delta_t=y-xsecs=delta_t.seconds+1def fourdlife():print "checking function"os.system("~/code/4dlife_repo/4dbatch/src/engines/extras/download_datos_desambiguar/news_Lucene.py")t = Timer(secs, fourdlife)
t.start()
print "timer started"

I am running this code in my ProcesosContinuous.py file like this:

while True:os.system("./runl.sh")#some other processes

where runl.sh is

python ~/code/4dlife_repo/4dbatch/src/engines/extras/download_datos_desambiguar/news_Lucene.py

This python code is always running on my apache2 server.

However, this is working at any given hour and not just the specified hour. What am I doing wrong? Also, I feel there is a much better way to do this. I looked at the cron task but that's not what I am looking for. I don't want my program to go to sleep() because I need the other processes to run after the runl.sh process. What is the best way to do this?

Answer

The command crontab -e will open up an interactive editor within which you can define a cron job.

Within that editor's buffer, you can then enter a line such as the following (and then save it):

00 00 * * * /path/to/script.sh

This command will run script.sh every midnight.

https://en.xdnf.cn/q/120691.html

Related Q&A

How to fix Error: Please select a valid Python interpreter in Pycharm?

Error:Error: Please select a valid Python interpreterScreenshot:How to fix this?

Tuples conversion into JSON with python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 8 years ago.Improve…

Python continue with while [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…

Create MySQL database with python [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Basic Python repetition exercise

I was trying to learn Python when I came upon this question. I am not asking for you to answer the question for me, I just need some help. Note: I am only allowed to use loops and if statements etc. No…

Python 3.3 socket programming error [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.Questions asking for code must demonstrate a minimal understanding of the problem being solved. Incl…

ValueError: math domain error

I wrote this codedef partE():e = 3 * 10 // 3 + 10 % 3print("e).", e)partE()and python comes back with this error message when I try to run it. I do not understand why. Can someone please expl…

how to access objects in python with for loop in different files

This is my file1.json: {"count": 1,"next": null,"previous": null,"results": [{"id": 5883,"url": "https://some.api.com/api/ipam/ip-addres…

multiplicative digital root of a number using loops

I need to find the multiplicative digital root of a number in python using only loops.something that does the same as the below code but using loops:print("multiplicative digital root of a number …

How to access key values in a json files dictionaries with python

I have a script that pulls json data from an api, and I want it to then after pulling said data, decode and pick which tags to store into a db. Right now I just need to get the script to return specifi…